Submission #561792

#TimeUsernameProblemLanguageResultExecution timeMemory
5617924fectaPower Plant (JOI20_power)C++17
0 / 100
4 ms4964 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 sum = 0; for (int nxt : a[cur]) { if (nxt == par) continue; dfs(nxt, cur); sum += dp[nxt]; } 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'; if (n == 2 && p[1] && p[2]) return 0 * printf("2\n"); for (int i = 1; i <= n; i++) { dfs(i, 0); 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...