Submission #1400654
Source Code Expand
#include <iostream> #include <vector> #include <map> #include <cmath> #include <algorithm> #include <queue> #include <unordered_set> #include <unordered_map> using namespace std; class TreeGraph { private: int n; int x; int ans; vector<int> h; vector<vector<int> > adj; public: TreeGraph() { cin >> n >> x; x--; h.resize(n); for (int i = 0; i < n; ++i) { cin >> h[i]; } adj.resize(n); for (int i = 0; i < n-1; ++i) { int a; int b; cin >> a >> b; a--; b--; adj[a].push_back(b); adj[b].push_back(a); } ans = 0; } bool dfs(int cur, int before) { bool flag = false; if(h[cur] == 1) flag = true; for (int i = 0; i < adj[cur].size(); ++i) { if(adj[cur][i] == before) continue; if(dfs(adj[cur][i], cur)) flag = true; } if(flag) ans += 2; return flag; } void exec() { for (int i = 0; i < adj[x].size(); ++i) { dfs(adj[x][i], x); } cout << ans << endl; } }; int main() { TreeGraph tg = TreeGraph(); tg.exec(); }
Submission Info
Submission Time | |
---|---|
Task | B - ツリーグラフ |
User | take1223xxx |
Language | C++14 (GCC 5.4.1) |
Score | 100 |
Code Size | 1064 Byte |
Status | AC |
Exec Time | 1 ms |
Memory | 256 KB |
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 | 1 ms | 256 KB |
subtask0_sample_02.txt | AC | 1 ms | 256 KB |
subtask1_line01.txt | AC | 1 ms | 256 KB |
subtask1_line02.txt | AC | 1 ms | 256 KB |
subtask1_line03.txt | AC | 1 ms | 256 KB |
subtask1_line04.txt | AC | 1 ms | 256 KB |
subtask1_line05.txt | AC | 1 ms | 256 KB |
subtask1_line06.txt | AC | 1 ms | 256 KB |
subtask1_random01.txt | AC | 1 ms | 256 KB |
subtask1_random02.txt | AC | 1 ms | 256 KB |
subtask1_random03.txt | AC | 1 ms | 256 KB |
subtask1_random04.txt | AC | 1 ms | 256 KB |
subtask1_random05.txt | AC | 1 ms | 256 KB |
subtask1_random06.txt | AC | 1 ms | 256 KB |
subtask1_random07.txt | AC | 1 ms | 256 KB |
subtask1_random08.txt | AC | 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 | AC | 1 ms | 256 KB |