Submission #335386

#TimeUsernameProblemLanguageResultExecution timeMemory
335386bluePower Plant (JOI20_power)C++11
0 / 100
6 ms8184 KiB
#include <iostream> #include <vector> #include <queue> using namespace std; int N; vector<int> edge[200001]; vector<int> plant(200000); vector<int> edge_count(200001, 0); vector<int> stream_count(200001, 0); vector<int> visit(200001, 0); int res = 0; int main() { cin >> N; int a, b; for(int i = 1; i <= N-1; i++) { cin >> a >> b; edge[a].push_back(b); edge_count[a]++; edge[b].push_back(a); edge_count[b]++; } char c; for(int i = 1; i <= N; i++) { cin >> c; plant[i] = (c == '1'); } queue<int> tbv; for(int i = 1; i <= N; i++) if(edge_count[i] == 1) { tbv.push(i); } while(!tbv.empty()) { a = tbv.front(); tbv.pop(); if(visit[a]) continue; visit[a] = 1; for(int v: edge[a]) { if(!visit[v]) { edge_count[v]--; if(edge_count[v] <= 1) { tbv.push(v); } } else { stream_count[a] += stream_count[v]; } } if(stream_count[a] > 1 && plant[a]) res--; if(stream_count[a] == 0 && plant[a]) { stream_count[a]++; res++; } } cout << res << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...