Submission #287317


Source Code Expand

Copy
#include <iostream>
#include <sstream>
#include <cstdio>
#include <map>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <list>
#include <stack>
#include <queue>
#include <cstdlib>
#include <tuple>
#define INF 1e9
#define EPS 1e-9
using namespace std;

typedef list<int> L;
typedef pair <int,int> P;
typedef vector<int> V;
typedef queue<int> Q;
typedef stack<int> S;
typedef map<string,int> M;

int main()
{
    int n, x;
    cin >> n >> x;
    V h(n);
    int sum = 0;
    for (auto &i : h) {
        cin >> i;
        if (i == 1) sum++;
    }

    vector<V> A(n+1, V(n+1,10000000));;
    for (int i = 0; i < n-1; i++) {
        int a, b;
        cin >> a >> b;
        A[a][b] = A[b][a] = 1;
    }
    for (int i = 0; i <= n; i++) {
        A[i][i] = 0;
    }

    Q p;
    for (int i = 1; i < A[x].size(); i++) {
        if (A[x][i] == 1) {
            p.push(i);
            A[i][0] = x;
        }
    }
    A[x][0] = 0;
    int res = 0;
    V d(n+1,0);
    while (p.size()) {
        int t = p.front(); p.pop();
        for (int i = 1; i < A[t].size(); i++) {
            if (A[t][0] != i && A[t][i] == 1) {
                p.push(i);
                A[i][0] = t;
            }
        }
        if (h[t-1] == 1) {
            res += d[A[t][0]] + 2;
        } else {
            d[t] = d[A[t][0]] + 2;
        }
    }

    cout << res << endl;

    return 0;
}

Submission Info

Submission Time
Task B - ツリーグラフ
User wanimaru47
Language C++11 (GCC 4.8.1)
Score 0
Code Size 1477 Byte
Status WA
Exec Time 53 ms
Memory 932 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 2
AC × 12
WA × 8
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 23 ms 732 KB
subtask0_sample_02.txt AC 22 ms 916 KB
subtask1_line01.txt AC 23 ms 716 KB
subtask1_line02.txt AC 22 ms 800 KB
subtask1_line03.txt AC 22 ms 796 KB
subtask1_line04.txt AC 22 ms 920 KB
subtask1_line05.txt AC 22 ms 932 KB
subtask1_line06.txt AC 23 ms 800 KB
subtask1_random01.txt WA 22 ms 932 KB
subtask1_random02.txt WA 21 ms 804 KB
subtask1_random03.txt WA 20 ms 924 KB
subtask1_random04.txt WA 23 ms 932 KB
subtask1_random05.txt WA 23 ms 800 KB
subtask1_random06.txt WA 23 ms 796 KB
subtask1_random07.txt WA 23 ms 924 KB
subtask1_random08.txt WA 21 ms 736 KB
subtask1_special01.txt AC 26 ms 804 KB
subtask1_special02.txt AC 24 ms 920 KB
subtask1_special03.txt AC 24 ms 792 KB
subtask1_special04.txt AC 53 ms 724 KB