Submission #1453767
Source Code Expand
#include<iostream> #include<vector> using namespace std; vector<int> v[100]; int h[100]; int n, x; int dfs(int pos, int par){ if(pos != x && v[pos].size() == 1){ return (h[pos] ? 1 : 0); }else{ int ret = 0; for(int u : v[pos]){ if(u != par){ int add = dfs(u, pos); ret += (add ? add + 1 : 0); } } return ret; } } int main(){ cin >> n >> x; --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; --b; v[a].push_back(b); v[b].push_back(a); } if(n == 1){ cout << 0 << endl; }else{ cout << dfs(x, -1) << endl; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | B - ツリーグラフ |
User | kcvlex |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 660 Byte |
Status | WA |
Exec Time | 1 ms |
Memory | 256 KB |
Judge Result
Set Name | Sample | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 100 | ||||||||
Status |
|
|
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 | WA | 1 ms | 256 KB |
subtask0_sample_02.txt | AC | 1 ms | 256 KB |
subtask1_line01.txt | AC | 1 ms | 256 KB |
subtask1_line02.txt | WA | 1 ms | 256 KB |
subtask1_line03.txt | WA | 1 ms | 256 KB |
subtask1_line04.txt | WA | 1 ms | 256 KB |
subtask1_line05.txt | WA | 1 ms | 256 KB |
subtask1_line06.txt | AC | 1 ms | 256 KB |
subtask1_random01.txt | WA | 1 ms | 256 KB |
subtask1_random02.txt | WA | 1 ms | 256 KB |
subtask1_random03.txt | WA | 1 ms | 256 KB |
subtask1_random04.txt | WA | 1 ms | 256 KB |
subtask1_random05.txt | WA | 1 ms | 256 KB |
subtask1_random06.txt | WA | 1 ms | 256 KB |
subtask1_random07.txt | WA | 1 ms | 256 KB |
subtask1_random08.txt | WA | 1 ms | 256 KB |
subtask1_special01.txt | AC | 1 ms | 256 KB |
subtask1_special02.txt | AC | 1 ms | 256 KB |
subtask1_special03.txt | AC | 1 ms | 256 KB |
subtask1_special04.txt | WA | 1 ms | 256 KB |