Submission #286970


Source Code Expand

Copy
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>

using namespace std;

vector<int> way[101];

int hou[101],ans=0,ba=0;

void dfs(int be,int now){
    if(hou[now]){
        ba=0;
    }
    for(int i=0;i<way[now].size();i++){
        if(way[now][i] != be){
            ba++; ans++;
            dfs(now,way[now][i]);
        }
    }
    if(ba){
        ans--;
        ba--;
    }else{
        ans++;
    }
    return;
}


int main(){
    int n,x,from,to;
    
    scanf("%d%d",&n,&x);
    
    for(int i=1;i<=n;i++)
        scanf("%d",&hou[i]);
    
    for(int i=1;i<n;i++){
        scanf("%d%d",&from,&to);
        way[from].push_back(to);
        way[to].push_back(from);
    }
    
    dfs(-1,x);
    
    printf("%d\n",ans-1);
    return 0;
}

Submission Info

Submission Time
Task B - ツリーグラフ
User goodbaton
Language C++ (G++ 4.6.4)
Score 100
Code Size 917 Byte
Status AC
Exec Time 32 ms
Memory 928 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:40:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:43:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:46:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]

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 804 KB
subtask0_sample_02.txt AC 23 ms 708 KB
subtask1_line01.txt AC 23 ms 924 KB
subtask1_line02.txt AC 21 ms 796 KB
subtask1_line03.txt AC 23 ms 728 KB
subtask1_line04.txt AC 23 ms 800 KB
subtask1_line05.txt AC 23 ms 736 KB
subtask1_line06.txt AC 22 ms 748 KB
subtask1_random01.txt AC 22 ms 804 KB
subtask1_random02.txt AC 21 ms 920 KB
subtask1_random03.txt AC 23 ms 796 KB
subtask1_random04.txt AC 23 ms 796 KB
subtask1_random05.txt AC 21 ms 896 KB
subtask1_random06.txt AC 20 ms 796 KB
subtask1_random07.txt AC 21 ms 800 KB
subtask1_random08.txt AC 22 ms 676 KB
subtask1_special01.txt AC 32 ms 796 KB
subtask1_special02.txt AC 22 ms 928 KB
subtask1_special03.txt AC 21 ms 924 KB
subtask1_special04.txt AC 23 ms 732 KB