Submission #316947

# Submission time Handle Problem Language Result Execution time Memory
316947 2020-10-28T16:33:19 Z manh9203 Power Plant (JOI20_power) C++17
100 / 100
211 ms 29732 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

const int N = 200005;

int n;
string s;
vector<int> adj[N];
int dp[N][2];

void dfs(int u, int p) {
	if (s[u] == '0') {
		for (int v : adj[u]) {
			if (v != p) {
				dfs(v, u);
				dp[u][0] += dp[v][0];
				dp[u][1] = max(dp[u][1], dp[v][1]);
			}
		}
		dp[u][1] = max(dp[u][1], dp[u][0]);
	} else {
		int sum0 = 0, max0 = 0, sum1 = 0, max1 = 0;
		for (int v : adj[u]) {
			if (v != p) {
				dfs(v, u);
				sum0 += dp[v][0]; max0 = max(max0, dp[v][0]);
				sum1 += dp[v][1]; max1 = max(max1, dp[v][1]);
			}
		}
		dp[u][0] = max(sum0 - 1, 1);
		dp[u][1] = max(max1, max(max0 + 1, dp[u][0]));
	}
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);

	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);
	}
	cin >> s; s = " " + s;

	dfs(1, 1);
	cout << max(dp[1][0], dp[1][1]);
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 4 ms 4992 KB Output is correct
3 Correct 4 ms 4992 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 4 ms 4992 KB Output is correct
7 Correct 4 ms 4992 KB Output is correct
8 Correct 5 ms 4992 KB Output is correct
9 Correct 4 ms 4992 KB Output is correct
10 Correct 4 ms 4992 KB Output is correct
11 Correct 4 ms 4992 KB Output is correct
12 Correct 4 ms 4992 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Correct 5 ms 4992 KB Output is correct
15 Correct 4 ms 4992 KB Output is correct
16 Correct 4 ms 4992 KB Output is correct
17 Correct 4 ms 4992 KB Output is correct
18 Correct 4 ms 4992 KB Output is correct
19 Correct 4 ms 4992 KB Output is correct
20 Correct 4 ms 4992 KB Output is correct
21 Correct 4 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 4 ms 4992 KB Output is correct
3 Correct 4 ms 4992 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 4 ms 4992 KB Output is correct
7 Correct 4 ms 4992 KB Output is correct
8 Correct 5 ms 4992 KB Output is correct
9 Correct 4 ms 4992 KB Output is correct
10 Correct 4 ms 4992 KB Output is correct
11 Correct 4 ms 4992 KB Output is correct
12 Correct 4 ms 4992 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Correct 5 ms 4992 KB Output is correct
15 Correct 4 ms 4992 KB Output is correct
16 Correct 4 ms 4992 KB Output is correct
17 Correct 4 ms 4992 KB Output is correct
18 Correct 4 ms 4992 KB Output is correct
19 Correct 4 ms 4992 KB Output is correct
20 Correct 4 ms 4992 KB Output is correct
21 Correct 4 ms 4992 KB Output is correct
22 Correct 5 ms 5120 KB Output is correct
23 Correct 4 ms 5120 KB Output is correct
24 Correct 5 ms 5120 KB Output is correct
25 Correct 5 ms 5120 KB Output is correct
26 Correct 5 ms 5120 KB Output is correct
27 Correct 5 ms 5120 KB Output is correct
28 Correct 5 ms 5120 KB Output is correct
29 Correct 4 ms 5248 KB Output is correct
30 Correct 4 ms 5248 KB Output is correct
31 Correct 5 ms 5120 KB Output is correct
32 Correct 5 ms 5120 KB Output is correct
33 Correct 4 ms 5120 KB Output is correct
34 Correct 5 ms 5120 KB Output is correct
35 Correct 5 ms 5120 KB Output is correct
36 Correct 5 ms 5120 KB Output is correct
37 Correct 5 ms 5120 KB Output is correct
38 Correct 5 ms 5120 KB Output is correct
39 Correct 5 ms 5248 KB Output is correct
40 Correct 4 ms 5120 KB Output is correct
41 Correct 5 ms 5248 KB Output is correct
42 Correct 5 ms 5128 KB Output is correct
43 Correct 5 ms 5120 KB Output is correct
44 Correct 5 ms 5120 KB Output is correct
45 Correct 4 ms 5120 KB Output is correct
46 Correct 5 ms 5120 KB Output is correct
47 Correct 4 ms 5120 KB Output is correct
48 Correct 5 ms 5248 KB Output is correct
49 Correct 5 ms 5248 KB Output is correct
50 Correct 5 ms 5120 KB Output is correct
51 Correct 5 ms 5120 KB Output is correct
52 Correct 6 ms 5120 KB Output is correct
53 Correct 5 ms 5120 KB Output is correct
54 Correct 5 ms 5120 KB Output is correct
55 Correct 5 ms 5120 KB Output is correct
56 Correct 5 ms 5120 KB Output is correct
57 Correct 5 ms 5248 KB Output is correct
58 Correct 4 ms 5120 KB Output is correct
59 Correct 5 ms 5120 KB Output is correct
60 Correct 5 ms 5248 KB Output is correct
61 Correct 4 ms 5120 KB Output is correct
62 Correct 5 ms 5248 KB Output is correct
63 Correct 5 ms 5196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 4 ms 4992 KB Output is correct
3 Correct 4 ms 4992 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 4 ms 4992 KB Output is correct
7 Correct 4 ms 4992 KB Output is correct
8 Correct 5 ms 4992 KB Output is correct
9 Correct 4 ms 4992 KB Output is correct
10 Correct 4 ms 4992 KB Output is correct
11 Correct 4 ms 4992 KB Output is correct
12 Correct 4 ms 4992 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Correct 5 ms 4992 KB Output is correct
15 Correct 4 ms 4992 KB Output is correct
16 Correct 4 ms 4992 KB Output is correct
17 Correct 4 ms 4992 KB Output is correct
18 Correct 4 ms 4992 KB Output is correct
19 Correct 4 ms 4992 KB Output is correct
20 Correct 4 ms 4992 KB Output is correct
21 Correct 4 ms 4992 KB Output is correct
22 Correct 5 ms 5120 KB Output is correct
23 Correct 4 ms 5120 KB Output is correct
24 Correct 5 ms 5120 KB Output is correct
25 Correct 5 ms 5120 KB Output is correct
26 Correct 5 ms 5120 KB Output is correct
27 Correct 5 ms 5120 KB Output is correct
28 Correct 5 ms 5120 KB Output is correct
29 Correct 4 ms 5248 KB Output is correct
30 Correct 4 ms 5248 KB Output is correct
31 Correct 5 ms 5120 KB Output is correct
32 Correct 5 ms 5120 KB Output is correct
33 Correct 4 ms 5120 KB Output is correct
34 Correct 5 ms 5120 KB Output is correct
35 Correct 5 ms 5120 KB Output is correct
36 Correct 5 ms 5120 KB Output is correct
37 Correct 5 ms 5120 KB Output is correct
38 Correct 5 ms 5120 KB Output is correct
39 Correct 5 ms 5248 KB Output is correct
40 Correct 4 ms 5120 KB Output is correct
41 Correct 5 ms 5248 KB Output is correct
42 Correct 5 ms 5128 KB Output is correct
43 Correct 5 ms 5120 KB Output is correct
44 Correct 5 ms 5120 KB Output is correct
45 Correct 4 ms 5120 KB Output is correct
46 Correct 5 ms 5120 KB Output is correct
47 Correct 4 ms 5120 KB Output is correct
48 Correct 5 ms 5248 KB Output is correct
49 Correct 5 ms 5248 KB Output is correct
50 Correct 5 ms 5120 KB Output is correct
51 Correct 5 ms 5120 KB Output is correct
52 Correct 6 ms 5120 KB Output is correct
53 Correct 5 ms 5120 KB Output is correct
54 Correct 5 ms 5120 KB Output is correct
55 Correct 5 ms 5120 KB Output is correct
56 Correct 5 ms 5120 KB Output is correct
57 Correct 5 ms 5248 KB Output is correct
58 Correct 4 ms 5120 KB Output is correct
59 Correct 5 ms 5120 KB Output is correct
60 Correct 5 ms 5248 KB Output is correct
61 Correct 4 ms 5120 KB Output is correct
62 Correct 5 ms 5248 KB Output is correct
63 Correct 5 ms 5196 KB Output is correct
64 Correct 189 ms 15992 KB Output is correct
65 Correct 177 ms 15988 KB Output is correct
66 Correct 181 ms 15968 KB Output is correct
67 Correct 190 ms 16084 KB Output is correct
68 Correct 188 ms 15968 KB Output is correct
69 Correct 190 ms 15984 KB Output is correct
70 Correct 172 ms 16128 KB Output is correct
71 Correct 178 ms 16000 KB Output is correct
72 Correct 180 ms 15952 KB Output is correct
73 Correct 193 ms 28660 KB Output is correct
74 Correct 201 ms 28532 KB Output is correct
75 Correct 177 ms 15920 KB Output is correct
76 Correct 182 ms 15996 KB Output is correct
77 Correct 187 ms 15984 KB Output is correct
78 Correct 195 ms 15988 KB Output is correct
79 Correct 190 ms 15996 KB Output is correct
80 Correct 193 ms 15860 KB Output is correct
81 Correct 163 ms 16372 KB Output is correct
82 Correct 166 ms 16052 KB Output is correct
83 Correct 199 ms 21112 KB Output is correct
84 Correct 195 ms 23300 KB Output is correct
85 Correct 191 ms 22912 KB Output is correct
86 Correct 201 ms 17396 KB Output is correct
87 Correct 175 ms 16736 KB Output is correct
88 Correct 163 ms 17260 KB Output is correct
89 Correct 174 ms 17284 KB Output is correct
90 Correct 178 ms 16984 KB Output is correct
91 Correct 180 ms 17240 KB Output is correct
92 Correct 171 ms 17620 KB Output is correct
93 Correct 173 ms 19904 KB Output is correct
94 Correct 172 ms 21720 KB Output is correct
95 Correct 155 ms 20396 KB Output is correct
96 Correct 171 ms 18656 KB Output is correct
97 Correct 159 ms 17044 KB Output is correct
98 Correct 176 ms 16612 KB Output is correct
99 Correct 167 ms 16368 KB Output is correct
100 Correct 164 ms 19552 KB Output is correct
101 Correct 168 ms 17520 KB Output is correct
102 Correct 156 ms 16832 KB Output is correct
103 Correct 170 ms 16532 KB Output is correct
104 Correct 117 ms 16876 KB Output is correct
105 Correct 200 ms 25460 KB Output is correct
106 Correct 111 ms 16752 KB Output is correct
107 Correct 124 ms 16812 KB Output is correct
108 Correct 202 ms 29424 KB Output is correct
109 Correct 117 ms 16816 KB Output is correct
110 Correct 211 ms 29732 KB Output is correct
111 Correct 168 ms 15900 KB Output is correct