Submission #516585

#TimeUsernameProblemLanguageResultExecution timeMemory
516585Cross_RatioPower Plant (JOI20_power)C++14
100 / 100
154 ms27148 KiB
#include <bits/stdc++.h> #define int long long using namespace std; vector<vector<int> > adj; int DP[200005]; bool type[200005]; int ans = 0; void dfs(int c, int p) { int sum = 0; DP[c] = type[c] ? 1 : 0; for(int n : adj[c]) { if(n==p) continue; dfs(n,c); sum += DP[n]; ans = max(ans, DP[n] + DP[c]); } DP[c] = max(DP[c],sum-DP[c]); ans = max(ans, DP[c]); } signed main() { cin.sync_with_stdio(false); cin.tie(0); cout.tie(0); int N; cin >> N; int i; adj.resize(N); for(i=0;i<N-1;i++) { int a, b; cin >>a >> b; adj[a-1].push_back(b-1); adj[b-1].push_back(a-1); } string s; cin >> s; for(i=0;i<N;i++) type[i] = s[i] == '1'; dfs(0, -1); cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...