Submission #307498

#TimeUsernameProblemLanguageResultExecution timeMemory
307498asifthegreatPower Plant (JOI20_power)C++14
0 / 100
6 ms7424 KiB
#include <bits/stdc++.h> using namespace std; const int N = 3e5; vector<int>graph[N]; int dp[N]; string s = ":"; int res = 0; void dfs(int v, int par){ int mx = 0; for(auto c : graph[v]){ if(c == par) continue; dfs(c, v); dp[v] += dp[c]; mx = max(mx, dp[c]); } if(s[v] == '1') res = max(res, 1+mx); else res = max(res, dp[v]); dp[v] -= s[v]-'0'; if(dp[v] <= 0 && s[v] == '1') dp[v] = 1; res = max(res, dp[v]); } int main(){ int n; cin >> n; for(int i = 1; i < n;i++){ int a,b; cin >> a >> b; graph[a].push_back(b); graph[b].push_back(a); } string t; cin >> t; dfs(1, 0); cout << res << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...