Contest Duration: - (local time) (90 minutes) Back to Home

Submission #286980

Source Code Expand

Copy
```#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>

#define INF 100000000
#define EPS 1e-9

using namespace std;

typedef long long ll;

#define MAX_N 100
int n, x;
int h[MAX_N];
int cnt = 0;
vector <int> d[MAX_N];

int ans = 0;

int solve(int s, int pre){

int num = 0;

for (int i = 0; i < d[s].size(); i++){
if (d[s][i] == pre)
continue;
num += solve(d[s][i], s);
}

if (s != x){
if (num >= 1){
return num + 1;
}
else if (h[s] == 1)
return 1;
else
return 0;
}

else{
return num;
}

}

int main(){

cin >> n >> x;
x--;
for (int i = 0; i < n; i++){
cin >> h[i];
if (h[i] == 1)
cnt++;
}
for (int i = 0; i < n-1; i++){
int a, b;
cin >> a >> b;
a--;
b--;
d[a].push_back(b);
d[b].push_back(a);
}

cout << solve(x, -1)*2 << endl;

return 0;

}```

#### Submission Info

Submission Time 2014-11-29 21:34:14+0900 B - ツリーグラフ taketake0609 C++ (G++ 4.6.4) 100 1254 Byte AC 25 ms 924 KB

#### Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
 AC × 2
 AC × 20
Set Name Test Cases
Case Name Status Exec Time Memory
subtask0_sample_01.txt AC 23 ms 732 KB
subtask0_sample_02.txt AC 25 ms 788 KB
subtask1_line01.txt AC 23 ms 792 KB
subtask1_line02.txt AC 22 ms 804 KB
subtask1_line03.txt AC 22 ms 800 KB
subtask1_line04.txt AC 22 ms 924 KB
subtask1_line05.txt AC 21 ms 796 KB
subtask1_line06.txt AC 23 ms 912 KB
subtask1_random01.txt AC 23 ms 920 KB
subtask1_random02.txt AC 22 ms 796 KB
subtask1_random03.txt AC 23 ms 672 KB
subtask1_random04.txt AC 20 ms 796 KB
subtask1_random05.txt AC 22 ms 916 KB
subtask1_random06.txt AC 21 ms 800 KB
subtask1_random07.txt AC 21 ms 924 KB
subtask1_random08.txt AC 22 ms 676 KB
subtask1_special01.txt AC 21 ms 672 KB
subtask1_special02.txt AC 22 ms 796 KB
subtask1_special03.txt AC 22 ms 796 KB
subtask1_special04.txt AC 20 ms 796 KB