Submission #287517


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 n;
int h[101];
int A[101][101];

int dfs (int x) {
    int res = 0;
    if (h[x-1] == 1) {
        res += 2;
    }
    for (int i = 1; i <= n; i++) {
        if (A[x][0] != i && A[x][i] == 1) {
            A[i][0] = x;
            res += dfs(i);
        }
    }
    if (res > 0 && h[x-1] != 1) res += 2;

    return res;
}

int main()
{
    int x;
    cin >> n >> x;
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }

    for (int i = 0; i < n-1; i++) {
        int a, b;
        cin >> a >> b;
        A[a][b] = A[b][a] = 1;
    }
    int res = 0;
    for (int i = 1; i <= n; i++) {
        if (A[x][i] == 1) {
            A[i][0] = x;
            res += dfs(i);
        }
    }

    cout << res << endl;

    return 0;
}

Submission Info

Submission Time
Task B - ツリーグラフ
User wanimaru47
Language C++11 (GCC 4.8.1)
Score 100
Code Size 1239 Byte
Status AC
Exec Time 23 ms
Memory 932 KB

Judge Result

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