Submission #885796

#TimeUsernameProblemLanguageResultExecution timeMemory
885796wkspPower Plant (JOI20_power)C++14
100 / 100
120 ms28724 KiB
#include<bits/stdc++.h> using namespace std; const int n_max = 2 * 1e5 + 7; vector<int> graph[n_max]; int power_generator[n_max]; int ans; int DFS(int v, int p){ int sum = 0; int max_vallue = 0; for(auto u: graph[v]){ if(u != p){ int vallue = DFS(u ,v); sum += vallue; max_vallue = max(max_vallue, vallue); } } int ans_tym = 0; if(power_generator[v] == 1){ ans_tym = max(sum - 1, 1); if(sum == max_vallue){ ans = max(ans, sum + 1); } if(sum == max_vallue + 1){ ans = max(ans, sum); } }else{ ans_tym = sum; } ans = max(ans, ans_tym); return ans_tym; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); ans = 0; int n; cin >> n; for(int i = 0; i < n - 1; i++){ int a, b; cin >> a >> b; graph[a].push_back(b); graph[b].push_back(a); } string s; cin >> s; for(int i = 0; i < n; i++){ if(s[i] == '1'){ power_generator[i+1] = 1; } } ans = 0; DFS(1, 0); cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...