Submission #617050

#TimeUsernameProblemLanguageResultExecution timeMemory
617050HanksburgerPower Plant (JOI20_power)C++17
100 / 100
175 ms29312 KiB
#include <bits/stdc++.h> using namespace std; int dp[200005], ok[200005], n, ans; vector<int> adj[200005]; void dfs(int u, int p) { int sum=0, mx=0; for (int v:adj[u]) { if (v==p) continue; dfs(v, u); sum+=dp[v]; mx=max(mx, dp[v]); } ans=max(ans, dp[u]=max(ok[u], sum-ok[u])); if (ok[u]) ans=max(ans, mx+1); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i=1; i<n; i++) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } for (int i=1; i<=n; i++) { char x; cin >> x; ok[i]=x-'0'; } dfs(1, 1); cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...