Submission #1686692


Source Code Expand

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int g[110][110];
vector<int> vec[100];
int n, x;
int h[110];
int tmp;
int used[110];

void bt(int nd) {
    used[nd] = 1;
    imfor(i, n) {
        if (g[nd][i] == 1 && used[i] == 0) {
            vec[nd].push_back(i);
            bt(i);
        }
    }
}

int check(int nd) {
    if (h[nd] == 1) {
        return 1;
    }
    for (auto x : vec[nd]) {
        if (h[x] == 1) {
            return 1;
        }
        if (check(x) == 1) {
            return 1;
        }
    }
    return 0;
}

void cnt(int rt) {
    for (auto x : vec[rt]) {
        if (check(x) == 1) {
            tmp += 2;
            cnt(x);
        }
    }
}

int main() {
    cin >> n >> x;
    imfor(i, n) {
        int hs;
        cin >> hs;
        h[i] = hs;
    }
    imfor(i, n) {
        imfor(j, n) {
            g[i][j] = 0;
        }
    }
    imfor(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a -= 1;
        b -= 1;
        g[a][b] = 1;
        g[b][a] = 1;
    }
    int ans = 99999999;
    imfor(i, n) {
        imfor(j, n) {
            vec[j].clear();
        }
        imfor(j, n) {
            used[j] = 0;
        }
        bt(i);
        tmp = 0;
        cnt(i);
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}

Submission Info

Submission Time
Task B - ツリーグラフ
User imaizumi14
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1734 Byte
Status WA
Exec Time 4 ms
Memory 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 2
AC × 13
WA × 7
Set Name Test Cases
Sample subtask0_sample_01.txt, subtask0_sample_02.txt
All subtask0_sample_01.txt, subtask0_sample_02.txt, subtask1_line01.txt, subtask1_line02.txt, subtask1_line03.txt, subtask1_line04.txt, subtask1_line05.txt, subtask1_line06.txt, subtask1_random01.txt, subtask1_random02.txt, subtask1_random03.txt, subtask1_random04.txt, subtask1_random05.txt, subtask1_random06.txt, subtask1_random07.txt, subtask1_random08.txt, subtask1_special01.txt, subtask1_special02.txt, subtask1_special03.txt, subtask1_special04.txt
Case Name Status Exec Time Memory
subtask0_sample_01.txt AC 1 ms 256 KB
subtask0_sample_02.txt AC 1 ms 256 KB
subtask1_line01.txt AC 1 ms 256 KB
subtask1_line02.txt WA 4 ms 256 KB
subtask1_line03.txt WA 2 ms 256 KB
subtask1_line04.txt WA 4 ms 256 KB
subtask1_line05.txt AC 4 ms 256 KB
subtask1_line06.txt AC 4 ms 256 KB
subtask1_random01.txt AC 4 ms 256 KB
subtask1_random02.txt WA 2 ms 256 KB
subtask1_random03.txt AC 2 ms 256 KB
subtask1_random04.txt WA 4 ms 256 KB
subtask1_random05.txt AC 4 ms 256 KB
subtask1_random06.txt WA 4 ms 256 KB
subtask1_random07.txt AC 4 ms 256 KB
subtask1_random08.txt WA 4 ms 256 KB
subtask1_special01.txt AC 1 ms 256 KB
subtask1_special02.txt AC 4 ms 256 KB
subtask1_special03.txt AC 4 ms 256 KB
subtask1_special04.txt AC 2 ms 256 KB