Submission #322560

#TimeUsernameProblemLanguageResultExecution timeMemory
322560arborPower Plant (JOI20_power)C++14
100 / 100
185 ms28972 KiB
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() using namespace std; using ll = long long; using pii = pair<int, int>; const int MN = 2e5 + 5; int N; string s; vector<int> g[MN]; int dp[MN], ans; void dfs(int u, int p) { int mx = 0; for (int v : g[u]) if (v != p) { dfs(v, u); dp[u] += dp[v]; mx = max(mx, dp[v]); } if (s[u - 1] == '1') { dp[u] = max(dp[u] - 1, 1); ans = max(ans, mx + 1); } ans = max(ans, dp[u]); } int main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> N; for (int i = 1; i < N; i++) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } cin >> s; dfs(1, -1); cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...