Submission #287023


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 dfs(int x,int cost){
    int retsum=0;
    check[x] = true;
    if(hoseki[x] == 1){
        retsum+=2*cost;
    }
    for(int i=0;i<dirc[x];i++){
        if(!check[dir[x][i]]){
            if(hoseki[x] == 1){
                retsum += dfs(dir[x][i], 1);
            }else{
                retsum += dfs(dir[x][i], cost+1);
            }
        }
    }
    return retsum;
}

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]++;
    }
    cout << dfs(x,0) << '\n';
    return 0;
}

Submission Info

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