Submission #962482

# Submission time Handle Problem Language Result Execution time Memory
962482 2024-04-13T16:04:03 Z 0npata Power Plant (JOI20_power) C++17
100 / 100
200 ms 29668 KB
#include<bits/stdc++.h>
using namespace std;

const int N = 200'000;

#define vec vector
#define pb push_back

int dp[N][2];
vec<int> tree[N];
string s;

void dfs(int u, int p = -1) {
	for(int v : tree[u]) {
		if(p==v) continue;

		dfs(v, u);
	}

	int a = 1; int b = -1; int c = 0;
	for(int v : tree[u]) {
		if(v==p) continue;
		a = max(dp[v][1]+1, a);
		b += dp[v][1];
		c = max(dp[v][0], c);
	}
	if(s[u] == '1') {
		dp[u][0] = max(max(a, b), c);
		dp[u][1] = max(b, 1);
	}
	else {
		dp[u][1] = b+1;
		dp[u][0] = max(c, b+1);
	}
}

int main() {
	int n;
	cin >> n;
	for(int i = 0; i<n-1; i++) {
		int u, v;
		cin >> u >> v;
		u--; v--;

		tree[u].pb(v);
		tree[v].pb(u);
	}

	cin >> s;

	dfs(0);

	cout << dp[0][0] << '\n';

}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 1 ms 4952 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 1 ms 4952 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 1 ms 4952 KB Output is correct
17 Correct 1 ms 5144 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 2 ms 4952 KB Output is correct
20 Correct 1 ms 5208 KB Output is correct
21 Correct 2 ms 5136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 1 ms 4952 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 1 ms 4952 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 1 ms 4952 KB Output is correct
17 Correct 1 ms 5144 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 2 ms 4952 KB Output is correct
20 Correct 1 ms 5208 KB Output is correct
21 Correct 2 ms 5136 KB Output is correct
22 Correct 3 ms 5212 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 2 ms 5004 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 5208 KB Output is correct
30 Correct 2 ms 5212 KB Output is correct
31 Correct 3 ms 5212 KB Output is correct
32 Correct 2 ms 5168 KB Output is correct
33 Correct 2 ms 5212 KB Output is correct
34 Correct 3 ms 5172 KB Output is correct
35 Correct 3 ms 5212 KB Output is correct
36 Correct 2 ms 5212 KB Output is correct
37 Correct 2 ms 5212 KB Output is correct
38 Correct 2 ms 5212 KB Output is correct
39 Correct 2 ms 5156 KB Output is correct
40 Correct 2 ms 5208 KB Output is correct
41 Correct 3 ms 5212 KB Output is correct
42 Correct 2 ms 5212 KB Output is correct
43 Correct 2 ms 5212 KB Output is correct
44 Correct 2 ms 5192 KB Output is correct
45 Correct 2 ms 5464 KB Output is correct
46 Correct 3 ms 5208 KB Output is correct
47 Correct 3 ms 5212 KB Output is correct
48 Correct 3 ms 5152 KB Output is correct
49 Correct 4 ms 5212 KB Output is correct
50 Correct 2 ms 5208 KB Output is correct
51 Correct 2 ms 5212 KB Output is correct
52 Correct 3 ms 5212 KB Output is correct
53 Correct 2 ms 5212 KB Output is correct
54 Correct 2 ms 5148 KB Output is correct
55 Correct 3 ms 5212 KB Output is correct
56 Correct 2 ms 5212 KB Output is correct
57 Correct 3 ms 5220 KB Output is correct
58 Correct 3 ms 5212 KB Output is correct
59 Correct 3 ms 5212 KB Output is correct
60 Correct 2 ms 5212 KB Output is correct
61 Correct 3 ms 5212 KB Output is correct
62 Correct 4 ms 5212 KB Output is correct
63 Correct 3 ms 5208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 1 ms 4952 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 1 ms 4952 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 1 ms 4952 KB Output is correct
17 Correct 1 ms 5144 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 2 ms 4952 KB Output is correct
20 Correct 1 ms 5208 KB Output is correct
21 Correct 2 ms 5136 KB Output is correct
22 Correct 3 ms 5212 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 2 ms 5004 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 5208 KB Output is correct
30 Correct 2 ms 5212 KB Output is correct
31 Correct 3 ms 5212 KB Output is correct
32 Correct 2 ms 5168 KB Output is correct
33 Correct 2 ms 5212 KB Output is correct
34 Correct 3 ms 5172 KB Output is correct
35 Correct 3 ms 5212 KB Output is correct
36 Correct 2 ms 5212 KB Output is correct
37 Correct 2 ms 5212 KB Output is correct
38 Correct 2 ms 5212 KB Output is correct
39 Correct 2 ms 5156 KB Output is correct
40 Correct 2 ms 5208 KB Output is correct
41 Correct 3 ms 5212 KB Output is correct
42 Correct 2 ms 5212 KB Output is correct
43 Correct 2 ms 5212 KB Output is correct
44 Correct 2 ms 5192 KB Output is correct
45 Correct 2 ms 5464 KB Output is correct
46 Correct 3 ms 5208 KB Output is correct
47 Correct 3 ms 5212 KB Output is correct
48 Correct 3 ms 5152 KB Output is correct
49 Correct 4 ms 5212 KB Output is correct
50 Correct 2 ms 5208 KB Output is correct
51 Correct 2 ms 5212 KB Output is correct
52 Correct 3 ms 5212 KB Output is correct
53 Correct 2 ms 5212 KB Output is correct
54 Correct 2 ms 5148 KB Output is correct
55 Correct 3 ms 5212 KB Output is correct
56 Correct 2 ms 5212 KB Output is correct
57 Correct 3 ms 5220 KB Output is correct
58 Correct 3 ms 5212 KB Output is correct
59 Correct 3 ms 5212 KB Output is correct
60 Correct 2 ms 5212 KB Output is correct
61 Correct 3 ms 5212 KB Output is correct
62 Correct 4 ms 5212 KB Output is correct
63 Correct 3 ms 5208 KB Output is correct
64 Correct 145 ms 16004 KB Output is correct
65 Correct 143 ms 16052 KB Output is correct
66 Correct 174 ms 16116 KB Output is correct
67 Correct 167 ms 15948 KB Output is correct
68 Correct 150 ms 16024 KB Output is correct
69 Correct 188 ms 15956 KB Output is correct
70 Correct 161 ms 15964 KB Output is correct
71 Correct 130 ms 15956 KB Output is correct
72 Correct 155 ms 16108 KB Output is correct
73 Correct 167 ms 28580 KB Output is correct
74 Correct 141 ms 28516 KB Output is correct
75 Correct 127 ms 15948 KB Output is correct
76 Correct 132 ms 15952 KB Output is correct
77 Correct 168 ms 15816 KB Output is correct
78 Correct 134 ms 15840 KB Output is correct
79 Correct 184 ms 15784 KB Output is correct
80 Correct 168 ms 16096 KB Output is correct
81 Correct 122 ms 16252 KB Output is correct
82 Correct 133 ms 16288 KB Output is correct
83 Correct 147 ms 20972 KB Output is correct
84 Correct 143 ms 23268 KB Output is correct
85 Correct 148 ms 22948 KB Output is correct
86 Correct 168 ms 17384 KB Output is correct
87 Correct 141 ms 16868 KB Output is correct
88 Correct 127 ms 17288 KB Output is correct
89 Correct 126 ms 17308 KB Output is correct
90 Correct 157 ms 17184 KB Output is correct
91 Correct 140 ms 17348 KB Output is correct
92 Correct 154 ms 17648 KB Output is correct
93 Correct 143 ms 20004 KB Output is correct
94 Correct 133 ms 21652 KB Output is correct
95 Correct 200 ms 20312 KB Output is correct
96 Correct 132 ms 18568 KB Output is correct
97 Correct 137 ms 17120 KB Output is correct
98 Correct 125 ms 16612 KB Output is correct
99 Correct 154 ms 16356 KB Output is correct
100 Correct 149 ms 19692 KB Output is correct
101 Correct 139 ms 17540 KB Output is correct
102 Correct 164 ms 16712 KB Output is correct
103 Correct 139 ms 16648 KB Output is correct
104 Correct 121 ms 16940 KB Output is correct
105 Correct 162 ms 25312 KB Output is correct
106 Correct 104 ms 16684 KB Output is correct
107 Correct 109 ms 16580 KB Output is correct
108 Correct 188 ms 29408 KB Output is correct
109 Correct 112 ms 16836 KB Output is correct
110 Correct 158 ms 29668 KB Output is correct
111 Correct 121 ms 15888 KB Output is correct