Submission #551615

#TimeUsernameProblemLanguageResultExecution timeMemory
551615Soumya1Power Plant (JOI20_power)C++17
100 / 100
204 ms26076 KiB
#include <bits/stdc++.h> #ifdef __LOCAL__ #include <debug_local.h> #endif using namespace std; const int mxN = 2e5 + 5; vector<int> ad[mxN]; string s; int dp[mxN]; int ans = 0; void dfs(int u, int p) { for (int v : ad[u]) { if (v == p) continue; dfs(v, u); } int x = 0; int val = s[u] - '0'; dp[u] = val; for (int v : ad[u]) { if (v == p) continue; dp[u] = max(dp[u], dp[v] - val); ans = max(ans, dp[v] + val); x += dp[v]; } dp[u] = max(dp[u], x - val); ans = max(ans, dp[u]); } void testCase() { int n; cin >> n; for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; ad[u].push_back(v); ad[v].push_back(u); } cin >> s; s = '#' + s; dfs(1, -1); cout << ans << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); testCase(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...