Submission #321402

#TimeUsernameProblemLanguageResultExecution timeMemory
321402shaf_wa_nurPower Plant (JOI20_power)C++14
100 / 100
194 ms34400 KiB
/** * author: shafwanur010 * created: 11/11/2020 10:23:47 PM (Bangladesh Standard Time) **/ #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<vector<int>> g(n + 1); for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } string s; cin >> s; s = '0' + s; int ans = 0; vector<int> dp(n + 1); function<void(int, int)> dfs = [&](int u, int p) { int sum = 0; for (int v : g[u]) { if (v != p) { dfs(v, u); sum += dp[v]; } } dp[u] = max(s[u] - '0', sum - (s[u] - '0')); ans = max({ans, dp[u], dp[u] + (s[p] - '0')}); }; dfs(1, 0); cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...