Submission #444914

#TimeUsernameProblemLanguageResultExecution timeMemory
444914dutchPower Plant (JOI20_power)C++17
100 / 100
193 ms24228 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5; int n, ans, dp[MAXN]; vector<int> g[MAXN]; string s; void dfs(int u, int p){ if(s[u] - '0') dp[u] = -1; for(int &v : g[u]){ if(v == p) continue; dfs(v, u); if(s[u] - '0') ans = max(ans, 1 + dp[v]); dp[u] += dp[v]; } dp[u] = max(dp[u], s[u] - '0'); ans = max(ans, dp[u]); } signed main(){ cin.tie(0)->sync_with_stdio(0); cin >> n; for(int i=1; i<n; ++i){ int u, v; cin >> u >> v; --u, --v; g[u].push_back(v); g[v].push_back(u); } cin >> s; dfs(0, 0); cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...