| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 514856 | ACE_ | Power Plant (JOI20_power) | C++14 | 284 ms | 28860 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int t, dp[maxn], n, ans;
vector<int> V[maxn];
string s;
void dfs(int u,int p) {
int m = 0, all = 0;
for(int i = 0; i < V[u].size(); i++) {
if(V[u][i] == p) continue;
dfs(V[u][i], u);
all += dp[V[u][i]];
m = max(m, dp[V[u][i]]);
}
dp[u] = max(m - (s[u] == '1'), 0 + (s[u] == '1'));
dp[u] = max(dp[u], all - (s[u] == '1'));
ans = max(ans, m + (s[u] == '1')); ans = max(ans, dp[u]);
}
main(){
cin >> n;
for(int i = 2; i <= n; i++) {
int u,v;
cin >> u >> v;
V[u].push_back(v); V[v].push_back(u);
}
cin >> s; s = '#' + s;
dfs(1, 0);
cout << max(ans, dp[1]);
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
