# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
529590 | MilosMilutinovic | Power Plant (JOI20_power) | C++14 | 183 ms | 28812 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>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
int n, dp[200005], ans;
vector<int> G[200005];
char s[200005];
void dfs(int v, int par)
{
rep(i, G[v].size()) {
int u = G[v][i];
if(u == par) continue;
dfs(u, v);
if(s[v] == '1') ans = max(ans, dp[u] + 1);
dp[v] += dp[u];
}
dp[v] -= (s[v] == '1' ? 1 : 0);
if(s[v] == '1') dp[v] = max(dp[v], 1);
ans = max(ans, dp[v]);
}
int main()
{
scanf("%d", &n);
rep(i, n - 1) {
int a, b;
scanf("%d%d", &a, &b);
G[a].push_back(b);
G[b].push_back(a);
}
scanf("%s", s + 1);
dfs(1, 0);
printf("%d", ans);
return 0;
}
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... |