Submission #503777

#TimeUsernameProblemLanguageResultExecution timeMemory
503777Abrar_Al_SamitPower Plant (JOI20_power)C++17
6 / 100
1567 ms5068 KiB
#include<bits/stdc++.h> using namespace std; const int MX = 200005; vector<int>g[MX]; int n; int dp[MX]; string s; int ans; int solve(int v, int p=-1) { int &ret = dp[v]; ret = 0; if(s[v]=='0') { for(auto u : g[v]) if(u!=p) { ret += solve(u, v); } } else { int mx = 0, sum = 0; for(auto u : g[v]) if(u!=p) { mx = max(mx, solve(u, v)); sum += solve(u, v); } mx += 1; sum -= 1; ans = max({mx, ans, sum}); ret = max(1, sum); } return ret; } 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; cout << max(ans, solve(1)) << 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...