# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
636819 | valerikk | Power Plant (JOI20_power) | C++17 | 181 ms | 32344 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 <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX_N = 200005;
void umax(int &a, int b) {
a = max(a, b);
}
int N;
vector<int> adj[MAX_N];
char S[MAX_N];
int D[MAX_N][2];
void DFS(int u, int p = -1) {
int sum[2] = {0, 0};
int mx[2] = {0, 0};
for(int v : adj[u]) {
if(v != p) {
DFS(v, u);
for(int i = 0; i < 2; ++i) {
sum[i] += D[v][i];
umax(mx[i], D[v][i]);
}
}
}
if(S[u] == '1') {
umax(D[u][0], sum[1] - 1);
umax(D[u][0], mx[0]);
umax(D[u][0], mx[1] + 1);
umax(D[u][0], 1);
umax(D[u][1], sum[1] - 1);
umax(D[u][1], 1);
} else {
umax(D[u][0], sum[1]);
umax(D[u][0], mx[0]);
umax(D[u][1], sum[1]);
}
}
int main() {
scanf("%d", &N);
for(int i = 0; i < N - 1; ++i) {
int A, B;
scanf("%d%d", &A, &B);
adj[A].push_back(B);
adj[B].push_back(A);
}
scanf("%s", S + 1);
DFS(1);
printf("%d\n", D[1][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... |