Submission #532739

#TimeUsernameProblemLanguageResultExecution timeMemory
532739Alex_tz307Power Plant (JOI20_power)C++17
0 / 100
3 ms5016 KiB
#include <bits/stdc++.h> using namespace std; const int kN = 2e5; vector<int> g[1 + kN]; string s; int dp[1 + kN]; void maxSelf(int &x, int y) { if (x < y) { x = y; } } void dfs(int u, int par) { dp[u] = s[u] - '0'; int sum = 0; for (int v : g[u]) { if (v != par) { dfs(v, u); sum += dp[v]; } } maxSelf(dp[u], 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; int ans = 0; for (int v = 1; v <= n; ++v) { dfs(v, 0); maxSelf(ans, dp[v]); } 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...