Submission #817956

#TimeUsernameProblemLanguageResultExecution timeMemory
817956tch1cherinPower Plant (JOI20_power)C++17
100 / 100
124 ms28888 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 2e5 + 5; vector<int> G[MAX_N]; int dp[MAX_N] = {}; string S; int ans; void DFS(int u, int p) { if (S[u] == '0') { for (int v : G[u]) { if (v != p) { DFS(v, u); dp[u] += dp[v]; } } ans = max(ans, dp[u]); } else { for (int v : G[u]) { if (v != p) { DFS(v, u); ans = max(ans, dp[v] + 1); dp[u] += dp[v]; } } if (dp[u] > 1) { dp[u] -= 1; } if (dp[u] == 0) { dp[u] += 1; } ans = max(ans, dp[u]); } } int main() { cin.tie(nullptr)->sync_with_stdio(false); int N; cin >> N; for (int i = 0; i < N - 1; i++) { int A, B; cin >> A >> B; A--, B--; G[A].push_back(B); G[B].push_back(A); } cin >> S; ans = 0; DFS(0, -1); cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...