Submission #287167


Source Code Expand

Copy
#include <iostream>
#define INF 9999999
using namespace std;
int n,x;
bool check[101];
int hoseki[101];
int dir[101][101];
int dirc[101];
int ans=0;

void dfs(int x){
    check[x] = true;
    for(int i=0;i<dirc[x];i++){
        if(!check[dir[x][i]]){
            dfs(dir[x][i]);
            if(hoseki[dir[x][i]] == 1){
                hoseki[x] = 1;
                ans += 2;
            }
        }
    }
}

int main(){
    cin >> n >> x;
    for(int i=1;i<=n;i++){
        check[i] = false;
        dirc[i] = 0;
        cin >> hoseki[i];
    }
    for(int i=0;i<n-1;i++){
        int a,b;
        cin >> a >> b;
        dir[a][dirc[a]] = b;
        dir[b][dirc[b]] = a;
        dirc[a]++;
        dirc[b]++;
    }
    dfs(x);
    cout << ans << '\n';
    return 0;
}

Submission Info

Submission Time
Task B - ツリーグラフ
User monman53
Language C++ (G++ 4.6.4)
Score 100
Code Size 811 Byte
Status AC
Exec Time 25 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 924 KB
subtask0_sample_02.txt AC 23 ms 804 KB
subtask1_line01.txt AC 25 ms 804 KB
subtask1_line02.txt AC 21 ms 796 KB
subtask1_line03.txt AC 23 ms 924 KB
subtask1_line04.txt AC 23 ms 800 KB
subtask1_line05.txt AC 21 ms 796 KB
subtask1_line06.txt AC 22 ms 928 KB
subtask1_random01.txt AC 23 ms 804 KB
subtask1_random02.txt AC 22 ms 932 KB
subtask1_random03.txt AC 21 ms 800 KB
subtask1_random04.txt AC 23 ms 932 KB
subtask1_random05.txt AC 23 ms 924 KB
subtask1_random06.txt AC 21 ms 920 KB
subtask1_random07.txt AC 22 ms 916 KB
subtask1_random08.txt AC 22 ms 804 KB
subtask1_special01.txt AC 21 ms 892 KB
subtask1_special02.txt AC 21 ms 928 KB
subtask1_special03.txt AC 21 ms 792 KB
subtask1_special04.txt AC 22 ms 804 KB