Submission #532750

#TimeUsernameProblemLanguageResultExecution timeMemory
532750Alex_tz307Power Plant (JOI20_power)C++17
100 / 100
183 ms28792 KiB
#include <bits/stdc++.h> using namespace std; const int kN = 2e5; vector<int> g[1 + kN]; string s; int ans, dp[1 + kN]; void maxSelf(int &x, int y) { if (x < y) { x = y; } } void dfs(int u, int par) { int best = 0, sum = 0; for (int v : g[u]) { if (v != par) { dfs(v, u); maxSelf(best, dp[v]); sum += dp[v]; } } maxSelf(ans, max(best + (s[u] - '0'), sum - (s[u] - '0'))); dp[u] = max(s[u] - '0', sum - (s[u] - '0')); } void testCase() { int n; cin >> n; for (int i = 1; i < n; ++i) { int u, v; cin >> u >> v; g[u].emplace_back(v); g[v].emplace_back(u); } cin >> s; s = '$' + s; dfs(1, 0); cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int tests = 1; for (int tc = 0; tc < tests; ++tc) { testCase(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...