Submission #503740

#TimeUsernameProblemLanguageResultExecution timeMemory
503740Abrar_Al_SamitPower Plant (JOI20_power)C++17
0 / 100
4 ms4940 KiB
#include<bits/stdc++.h> using namespace std; const int MX = 200005; vector<int>g[MX]; int n; int sub[MX]; string s; int ans; int DFS(int v, int p=0) { int cnt = 0; for(int u : g[v]) if(u!=p) { int get = DFS(u, v); if(get) ++cnt; sub[v] += get; } if(cnt<2 && sub[v]<2 && s[v]=='1') { ++ans; ++sub[v]; } return sub[v]; } void PlayGround() { cin >> n; for(int i=1; i<n; ++i) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } cin >> s; s = "#" + s; DFS(1); cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); PlayGround(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...