Submission #766740

#TimeUsernameProblemLanguageResultExecution timeMemory
766740DorostPower Plant (JOI20_power)C++17
0 / 100
3 ms4948 KiB
/* * In the name of GOD */ #include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair <int, int> pii; #define F first #define S second #define mk make_pair const int N = 201234; vector <int> g[N]; int dp[N][2]; bool f[N]; void dfs (int v, int p = -1) { if (f[v]) { dp[v][1] = 1; } int sum1 = 0; for (int u : g[v]) { if (u != p) { dfs (u, v); dp[v][0] = max(dp[u][0], dp[v][0]); if (f[v]) dp[v][0] = max(dp[u][1] + 1, dp[v][0]); sum1 += dp[u][1]; } } if (f[v]) { dp[v][0] = max(dp[v][0], sum1 - 1); dp[v][1] = max(dp[v][1], sum1 - 1); } else { dp[v][1] = max(dp[v][1], sum1); dp[v][0] = max(dp[v][0], sum1); } } int32_t main() { ios::sync_with_stdio(false); cin.tie(); cout.tie(); int n; cin >> n; for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } for (int i = 1; i <= n; i++) { char c; cin >> c; f[i] = (c - '0'); } dfs (1); cout << dp[1][0]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...