Submission #399952

# Submission time Handle Problem Language Result Execution time Memory
399952 2021-05-07T00:36:05 Z nikatamliani Power Plant (JOI20_power) C++14
100 / 100
168 ms 31592 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
vector<int> edges[N];
int dp[N], ans, n;
string s;
void solve(int x, int p) {
	int sum = 0, maxi = 0;
	for(int to : edges[x]) {
		if(to != p) {
			solve(to, x);
			sum += dp[to];
			maxi = max(maxi, dp[to]);
		}
	}
	if(s[x] == '1') {
		dp[x] = max(sum-1, 1);
		ans = max(ans, maxi+1);
		ans = max(ans, sum-1);
	} else {
		dp[x] = sum;
		ans = max(ans, sum);
	}
	ans = max(ans, dp[x]);
}
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for(int i = 0; i < n-1; ++i) {
		int u, v; cin >> u >> v;
		edges[u].push_back(v);
		edges[v].push_back(u);
	}
	cin >> s; s = "@" + s;
	solve(1, 0);
	cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 5024 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4908 KB Output is correct
13 Correct 3 ms 5060 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 5020 KB Output is correct
16 Correct 3 ms 5028 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 3 ms 5024 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 5024 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4908 KB Output is correct
13 Correct 3 ms 5060 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 5020 KB Output is correct
16 Correct 3 ms 5028 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 3 ms 5024 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 4 ms 5068 KB Output is correct
23 Correct 4 ms 5068 KB Output is correct
24 Correct 4 ms 5068 KB Output is correct
25 Correct 4 ms 5068 KB Output is correct
26 Correct 4 ms 5068 KB Output is correct
27 Correct 4 ms 5068 KB Output is correct
28 Correct 5 ms 5120 KB Output is correct
29 Correct 4 ms 5196 KB Output is correct
30 Correct 4 ms 5168 KB Output is correct
31 Correct 4 ms 5068 KB Output is correct
32 Correct 4 ms 5040 KB Output is correct
33 Correct 4 ms 5068 KB Output is correct
34 Correct 4 ms 5068 KB Output is correct
35 Correct 4 ms 5036 KB Output is correct
36 Correct 4 ms 5068 KB Output is correct
37 Correct 4 ms 5068 KB Output is correct
38 Correct 4 ms 5068 KB Output is correct
39 Correct 4 ms 5196 KB Output is correct
40 Correct 4 ms 5068 KB Output is correct
41 Correct 4 ms 5196 KB Output is correct
42 Correct 4 ms 5044 KB Output is correct
43 Correct 4 ms 5068 KB Output is correct
44 Correct 4 ms 5068 KB Output is correct
45 Correct 4 ms 5068 KB Output is correct
46 Correct 4 ms 5068 KB Output is correct
47 Correct 4 ms 5068 KB Output is correct
48 Correct 4 ms 5196 KB Output is correct
49 Correct 4 ms 5196 KB Output is correct
50 Correct 4 ms 5168 KB Output is correct
51 Correct 4 ms 5172 KB Output is correct
52 Correct 4 ms 5040 KB Output is correct
53 Correct 4 ms 5068 KB Output is correct
54 Correct 5 ms 5068 KB Output is correct
55 Correct 4 ms 5068 KB Output is correct
56 Correct 4 ms 5040 KB Output is correct
57 Correct 4 ms 5196 KB Output is correct
58 Correct 4 ms 5068 KB Output is correct
59 Correct 4 ms 5068 KB Output is correct
60 Correct 4 ms 5164 KB Output is correct
61 Correct 4 ms 5068 KB Output is correct
62 Correct 4 ms 5200 KB Output is correct
63 Correct 4 ms 5068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 5024 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4908 KB Output is correct
13 Correct 3 ms 5060 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 5020 KB Output is correct
16 Correct 3 ms 5028 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 3 ms 5024 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 4 ms 5068 KB Output is correct
23 Correct 4 ms 5068 KB Output is correct
24 Correct 4 ms 5068 KB Output is correct
25 Correct 4 ms 5068 KB Output is correct
26 Correct 4 ms 5068 KB Output is correct
27 Correct 4 ms 5068 KB Output is correct
28 Correct 5 ms 5120 KB Output is correct
29 Correct 4 ms 5196 KB Output is correct
30 Correct 4 ms 5168 KB Output is correct
31 Correct 4 ms 5068 KB Output is correct
32 Correct 4 ms 5040 KB Output is correct
33 Correct 4 ms 5068 KB Output is correct
34 Correct 4 ms 5068 KB Output is correct
35 Correct 4 ms 5036 KB Output is correct
36 Correct 4 ms 5068 KB Output is correct
37 Correct 4 ms 5068 KB Output is correct
38 Correct 4 ms 5068 KB Output is correct
39 Correct 4 ms 5196 KB Output is correct
40 Correct 4 ms 5068 KB Output is correct
41 Correct 4 ms 5196 KB Output is correct
42 Correct 4 ms 5044 KB Output is correct
43 Correct 4 ms 5068 KB Output is correct
44 Correct 4 ms 5068 KB Output is correct
45 Correct 4 ms 5068 KB Output is correct
46 Correct 4 ms 5068 KB Output is correct
47 Correct 4 ms 5068 KB Output is correct
48 Correct 4 ms 5196 KB Output is correct
49 Correct 4 ms 5196 KB Output is correct
50 Correct 4 ms 5168 KB Output is correct
51 Correct 4 ms 5172 KB Output is correct
52 Correct 4 ms 5040 KB Output is correct
53 Correct 4 ms 5068 KB Output is correct
54 Correct 5 ms 5068 KB Output is correct
55 Correct 4 ms 5068 KB Output is correct
56 Correct 4 ms 5040 KB Output is correct
57 Correct 4 ms 5196 KB Output is correct
58 Correct 4 ms 5068 KB Output is correct
59 Correct 4 ms 5068 KB Output is correct
60 Correct 4 ms 5164 KB Output is correct
61 Correct 4 ms 5068 KB Output is correct
62 Correct 4 ms 5200 KB Output is correct
63 Correct 4 ms 5068 KB Output is correct
64 Correct 131 ms 15152 KB Output is correct
65 Correct 131 ms 15132 KB Output is correct
66 Correct 135 ms 15196 KB Output is correct
67 Correct 129 ms 15168 KB Output is correct
68 Correct 137 ms 15148 KB Output is correct
69 Correct 130 ms 15112 KB Output is correct
70 Correct 129 ms 15184 KB Output is correct
71 Correct 129 ms 15092 KB Output is correct
72 Correct 140 ms 15164 KB Output is correct
73 Correct 146 ms 30272 KB Output is correct
74 Correct 154 ms 30272 KB Output is correct
75 Correct 126 ms 15036 KB Output is correct
76 Correct 128 ms 15024 KB Output is correct
77 Correct 136 ms 15052 KB Output is correct
78 Correct 133 ms 15036 KB Output is correct
79 Correct 134 ms 15016 KB Output is correct
80 Correct 131 ms 15060 KB Output is correct
81 Correct 110 ms 15492 KB Output is correct
82 Correct 122 ms 15192 KB Output is correct
83 Correct 140 ms 21256 KB Output is correct
84 Correct 158 ms 23964 KB Output is correct
85 Correct 148 ms 23452 KB Output is correct
86 Correct 137 ms 16756 KB Output is correct
87 Correct 137 ms 16060 KB Output is correct
88 Correct 141 ms 16608 KB Output is correct
89 Correct 125 ms 16548 KB Output is correct
90 Correct 133 ms 16272 KB Output is correct
91 Correct 159 ms 16608 KB Output is correct
92 Correct 147 ms 16936 KB Output is correct
93 Correct 129 ms 19848 KB Output is correct
94 Correct 124 ms 22028 KB Output is correct
95 Correct 126 ms 20316 KB Output is correct
96 Correct 142 ms 18272 KB Output is correct
97 Correct 132 ms 16280 KB Output is correct
98 Correct 124 ms 15700 KB Output is correct
99 Correct 133 ms 15548 KB Output is correct
100 Correct 131 ms 19368 KB Output is correct
101 Correct 137 ms 16980 KB Output is correct
102 Correct 123 ms 16012 KB Output is correct
103 Correct 132 ms 15740 KB Output is correct
104 Correct 83 ms 16028 KB Output is correct
105 Correct 168 ms 26572 KB Output is correct
106 Correct 83 ms 15924 KB Output is correct
107 Correct 82 ms 15876 KB Output is correct
108 Correct 160 ms 31272 KB Output is correct
109 Correct 84 ms 16056 KB Output is correct
110 Correct 163 ms 31592 KB Output is correct
111 Correct 128 ms 15044 KB Output is correct