Submission #1097080

# Submission time Handle Problem Language Result Execution time Memory
1097080 2024-10-06T03:19:17 Z anmattroi Power Plant (JOI20_power) C++14
100 / 100
83 ms 28760 KB
#include <bits/stdc++.h>

#define maxn 200005

using namespace std;

int n;
vector<int> adj[maxn];
int f[maxn], g[maxn];

char a[maxn];
int ds = 0;
int E[maxn];


void dfs(int u, int dad) {
    int sum = 0, mx = 0;
    for (int v : adj[u]) {
        if (v == dad) continue;
        dfs(v, u);
        mx = max(mx, f[v]);
        sum += f[v];
    }
    if (E[u] == 1) ds = max(ds, max(mx+1, sum-1));
    else ds = max(ds, sum);
    f[u] = max(E[u], sum-E[u]);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        if (a[i] == '1') E[i] = 1;
    }
    dfs(1, 0);
    cout << ds;

}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4960 KB Output is correct
2 Correct 3 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 5160 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4952 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 4 ms 5208 KB Output is correct
11 Correct 2 ms 4952 KB Output is correct
12 Correct 3 ms 5108 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 3 ms 4952 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4960 KB Output is correct
2 Correct 3 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 5160 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4952 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 4 ms 5208 KB Output is correct
11 Correct 2 ms 4952 KB Output is correct
12 Correct 3 ms 5108 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 3 ms 4952 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 3 ms 5208 KB Output is correct
23 Correct 3 ms 5212 KB Output is correct
24 Correct 2 ms 5212 KB Output is correct
25 Correct 3 ms 5212 KB Output is correct
26 Correct 3 ms 5212 KB Output is correct
27 Correct 2 ms 5212 KB Output is correct
28 Correct 2 ms 5212 KB Output is correct
29 Correct 3 ms 5212 KB Output is correct
30 Correct 3 ms 5212 KB Output is correct
31 Correct 2 ms 5212 KB Output is correct
32 Correct 3 ms 5212 KB Output is correct
33 Correct 3 ms 5212 KB Output is correct
34 Correct 3 ms 5212 KB Output is correct
35 Correct 3 ms 5212 KB Output is correct
36 Correct 3 ms 5212 KB Output is correct
37 Correct 3 ms 5212 KB Output is correct
38 Correct 3 ms 5212 KB Output is correct
39 Correct 3 ms 5284 KB Output is correct
40 Correct 2 ms 5220 KB Output is correct
41 Correct 3 ms 5308 KB Output is correct
42 Correct 3 ms 5212 KB Output is correct
43 Correct 3 ms 5212 KB Output is correct
44 Correct 2 ms 5212 KB Output is correct
45 Correct 2 ms 5212 KB Output is correct
46 Correct 3 ms 5212 KB Output is correct
47 Correct 3 ms 5212 KB Output is correct
48 Correct 3 ms 5212 KB Output is correct
49 Correct 2 ms 5212 KB Output is correct
50 Correct 2 ms 5212 KB Output is correct
51 Correct 3 ms 5208 KB Output is correct
52 Correct 3 ms 5208 KB Output is correct
53 Correct 3 ms 5208 KB Output is correct
54 Correct 2 ms 5208 KB Output is correct
55 Correct 3 ms 5212 KB Output is correct
56 Correct 2 ms 5212 KB Output is correct
57 Correct 2 ms 5212 KB Output is correct
58 Correct 2 ms 5464 KB Output is correct
59 Correct 2 ms 5212 KB Output is correct
60 Correct 2 ms 5224 KB Output is correct
61 Correct 2 ms 5212 KB Output is correct
62 Correct 2 ms 5212 KB Output is correct
63 Correct 3 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4960 KB Output is correct
2 Correct 3 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 5160 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4952 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 4 ms 5208 KB Output is correct
11 Correct 2 ms 4952 KB Output is correct
12 Correct 3 ms 5108 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 3 ms 4952 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 3 ms 5208 KB Output is correct
23 Correct 3 ms 5212 KB Output is correct
24 Correct 2 ms 5212 KB Output is correct
25 Correct 3 ms 5212 KB Output is correct
26 Correct 3 ms 5212 KB Output is correct
27 Correct 2 ms 5212 KB Output is correct
28 Correct 2 ms 5212 KB Output is correct
29 Correct 3 ms 5212 KB Output is correct
30 Correct 3 ms 5212 KB Output is correct
31 Correct 2 ms 5212 KB Output is correct
32 Correct 3 ms 5212 KB Output is correct
33 Correct 3 ms 5212 KB Output is correct
34 Correct 3 ms 5212 KB Output is correct
35 Correct 3 ms 5212 KB Output is correct
36 Correct 3 ms 5212 KB Output is correct
37 Correct 3 ms 5212 KB Output is correct
38 Correct 3 ms 5212 KB Output is correct
39 Correct 3 ms 5284 KB Output is correct
40 Correct 2 ms 5220 KB Output is correct
41 Correct 3 ms 5308 KB Output is correct
42 Correct 3 ms 5212 KB Output is correct
43 Correct 3 ms 5212 KB Output is correct
44 Correct 2 ms 5212 KB Output is correct
45 Correct 2 ms 5212 KB Output is correct
46 Correct 3 ms 5212 KB Output is correct
47 Correct 3 ms 5212 KB Output is correct
48 Correct 3 ms 5212 KB Output is correct
49 Correct 2 ms 5212 KB Output is correct
50 Correct 2 ms 5212 KB Output is correct
51 Correct 3 ms 5208 KB Output is correct
52 Correct 3 ms 5208 KB Output is correct
53 Correct 3 ms 5208 KB Output is correct
54 Correct 2 ms 5208 KB Output is correct
55 Correct 3 ms 5212 KB Output is correct
56 Correct 2 ms 5212 KB Output is correct
57 Correct 2 ms 5212 KB Output is correct
58 Correct 2 ms 5464 KB Output is correct
59 Correct 2 ms 5212 KB Output is correct
60 Correct 2 ms 5224 KB Output is correct
61 Correct 2 ms 5212 KB Output is correct
62 Correct 2 ms 5212 KB Output is correct
63 Correct 3 ms 5212 KB Output is correct
64 Correct 62 ms 15828 KB Output is correct
65 Correct 65 ms 16000 KB Output is correct
66 Correct 62 ms 15784 KB Output is correct
67 Correct 60 ms 15824 KB Output is correct
68 Correct 62 ms 15952 KB Output is correct
69 Correct 58 ms 15800 KB Output is correct
70 Correct 61 ms 15952 KB Output is correct
71 Correct 56 ms 15952 KB Output is correct
72 Correct 61 ms 15004 KB Output is correct
73 Correct 83 ms 28496 KB Output is correct
74 Correct 77 ms 28496 KB Output is correct
75 Correct 60 ms 15676 KB Output is correct
76 Correct 70 ms 15696 KB Output is correct
77 Correct 67 ms 15700 KB Output is correct
78 Correct 64 ms 15860 KB Output is correct
79 Correct 59 ms 15700 KB Output is correct
80 Correct 58 ms 15696 KB Output is correct
81 Correct 58 ms 16224 KB Output is correct
82 Correct 54 ms 16088 KB Output is correct
83 Correct 66 ms 21048 KB Output is correct
84 Correct 73 ms 23120 KB Output is correct
85 Correct 66 ms 22756 KB Output is correct
86 Correct 61 ms 17236 KB Output is correct
87 Correct 58 ms 16724 KB Output is correct
88 Correct 64 ms 16980 KB Output is correct
89 Correct 60 ms 17232 KB Output is correct
90 Correct 64 ms 16976 KB Output is correct
91 Correct 71 ms 17020 KB Output is correct
92 Correct 68 ms 17488 KB Output is correct
93 Correct 61 ms 19920 KB Output is correct
94 Correct 57 ms 21372 KB Output is correct
95 Correct 58 ms 20296 KB Output is correct
96 Correct 59 ms 18348 KB Output is correct
97 Correct 56 ms 16980 KB Output is correct
98 Correct 66 ms 16468 KB Output is correct
99 Correct 72 ms 16168 KB Output is correct
100 Correct 60 ms 19512 KB Output is correct
101 Correct 64 ms 17632 KB Output is correct
102 Correct 55 ms 16512 KB Output is correct
103 Correct 63 ms 16464 KB Output is correct
104 Correct 44 ms 15812 KB Output is correct
105 Correct 66 ms 24472 KB Output is correct
106 Correct 42 ms 16580 KB Output is correct
107 Correct 43 ms 16580 KB Output is correct
108 Correct 76 ms 28496 KB Output is correct
109 Correct 50 ms 15816 KB Output is correct
110 Correct 76 ms 28760 KB Output is correct
111 Correct 58 ms 15944 KB Output is correct