Submission #561793

#TimeUsernameProblemLanguageResultExecution timeMemory
5617934fectaPower Plant (JOI20_power)C++17
47 / 100
1586 ms18208 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define int ll #define ld long double #define pii pair<int, int> #define f first #define s second #define boost() cin.tie(0), cin.sync_with_stdio(0) const int MN = 200005; int n, u, v, p[MN], dp[MN], ans; char c; vector<int> a[MN]; void dfs(int cur, int par, int rt) { int sum = 0; for (int nxt : a[cur]) { if (nxt == par) continue; dfs(nxt, cur, rt); sum += dp[nxt]; } if (p[cur] && cur == rt) { if (a[rt].size() == 1) dp[cur] = sum + 1; else dp[cur] = max(1ll, sum - 1); } else if (p[cur]) dp[cur] = max(1ll, sum - 1); else dp[cur] = sum; } int32_t main() { boost(); cin >> n; for (int i = 1; i < n; i++) { cin >> u >> v; a[u].push_back(v); a[v].push_back(u); } for (int i = 1; i <= n; i++) cin >> c, p[i] = c - '0'; for (int i = 1; i <= n; i++) { dfs(i, 0, i); ans = max(ans, dp[i]); } printf("%lld\n", ans); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...