Submission #963806

#TimeUsernameProblemLanguageResultExecution timeMemory
963806Trisanu_DasPower Plant (JOI20_power)C++17
100 / 100
182 ms30440 KiB
#include<bits/stdc++.h> using namespace std; int n, x, y, ans = 0, dp[200001]; vector<int> vec[200001]; string s; bool visited[200001]; void dfs(int x) { int maxi = 0; visited[x] = true; for(int c : vec[x]) { if(!visited[c]) { dfs(c); dp[x] += dp[c]; maxi = max(dp[c], maxi); } } dp[x] = max(s[x - 1] - '0', dp[x] - s[x - 1] + '0'); ans = max(ans, max(maxi + s[x - 1] - '0', dp[x])); } int main() { cin >> n; for(int i = 1; i < n; i++) { cin >> x >> y; vec[x].push_back(y); vec[y].push_back(x); } cin >> s; dfs(n); cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...