Submission #766754

#TimeUsernameProblemLanguageResultExecution timeMemory
766754DorostPower Plant (JOI20_power)C++17
0 / 100
4 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]; bool f[N]; void dfs (int v, int p = -1) { dp[v] = f[v]; int sum1 = 0; for (int u : g[v]) { if (u != p) { dfs (u, v); sum1 += dp[u]; } } if (f[v]) { dp[v] = max(dp[v], sum1 - 1); } else { dp[v] = max(dp[v], sum1); } } int32_t main() { ios::sync_with_stdio(false); cin.tie(); cout.tie(); int n; cin >> n; if (n > 2000) return 0; 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'); } int mx = 0; for (int i = 1; i <= n; i++) { if (!f[i]) continue; dfs (i); for (int j : g[i]) { mx = max(mx, dp[j] + 1); } } cout << mx; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...