Submission #286812
Source Code Expand
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cctype> #include<cstdlib> #include<algorithm> #include<bitset> #include<vector> #include<list> #include<deque> #include<queue> #include<map> #include<set> #include<stack> #include<cmath> #include<sstream> #include<fstream> #include<iomanip> #include<ctime> #include<complex> #include<functional> #include<climits> #include<cassert> #include<iterator> using namespace std; struct st{ int go; int r; st(int go_, int r_){ go = go_; r = r_; } }; int n = 0; int x = 0; vector<int> v[101]; int flag[101]; vector<st> g[101]; bool use[101]; int dfs(int b){ use[b] = 1; int r = 0; for (int j = 0; j < v[b].size(); j++){ if (use[v[b][j]] == 0){ int kari = dfs(v[b][j]); g[b].push_back(st(v[b][j],kari) ); r += kari; } } r += flag[b]; return r; } bool use1[101]; int countt = 0; void ddf(int b){ countt++; use[b] = 1; for (int j = 0; j < g[b].size(); j++){ if (g[b][j].r){ ddf(g[b][j].go); countt++; } } } int main(){ scanf("%d%d", &n, &x); x--; for (int i = 0; i < n; i++){ cin >> flag[i]; } for (int i = 0; i < n - 1; i++){ int kari, kari1; cin >> kari >> kari1; kari--; kari1--; v[kari].push_back(kari1); v[kari1].push_back(kari); } int f=dfs(x); if (f == 0){ cout << 0 << endl; return 0; } ddf(x); cout << countt-1 << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | B - ツリーグラフ |
User | Kmcode |
Language | C++ (G++ 4.6.4) |
Score | 100 |
Code Size | 1466 Byte |
Status | AC |
Exec Time | 23 ms |
Memory | 932 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:67:23: 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 |
|
|
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 | 23 ms | 928 KB |
subtask0_sample_02.txt | AC | 22 ms | 924 KB |
subtask1_line01.txt | AC | 22 ms | 804 KB |
subtask1_line02.txt | AC | 22 ms | 804 KB |
subtask1_line03.txt | AC | 23 ms | 800 KB |
subtask1_line04.txt | AC | 21 ms | 924 KB |
subtask1_line05.txt | AC | 23 ms | 924 KB |
subtask1_line06.txt | AC | 22 ms | 932 KB |
subtask1_random01.txt | AC | 23 ms | 928 KB |
subtask1_random02.txt | AC | 22 ms | 804 KB |
subtask1_random03.txt | AC | 22 ms | 800 KB |
subtask1_random04.txt | AC | 22 ms | 928 KB |
subtask1_random05.txt | AC | 22 ms | 804 KB |
subtask1_random06.txt | AC | 22 ms | 928 KB |
subtask1_random07.txt | AC | 22 ms | 804 KB |
subtask1_random08.txt | AC | 21 ms | 924 KB |
subtask1_special01.txt | AC | 23 ms | 800 KB |
subtask1_special02.txt | AC | 22 ms | 816 KB |
subtask1_special03.txt | AC | 23 ms | 732 KB |
subtask1_special04.txt | AC | 22 ms | 928 KB |