# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
684946 |
2023-01-22T21:44:19 Z |
NK_ |
Power Plant (JOI20_power) |
C++17 |
|
177 ms |
29632 KB |
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
int main() {
cin.tie(0)->sync_with_stdio(0);
int N; cin >> N;
vector<vector<int>> adj(N);
for(int i = 0; i < N-1; i++) {
int u, v; cin >> u >> v; --u, --v;
adj[u].push_back(v);
adj[v].push_back(u);
}
string S; cin >> S;
vector<int> on(N); for(int i = 0; i < N; i++) on[i] = S[i] - '0';
vector<int> dp(N, 0);
function<void(int, int)> gen = [&](int u, int p) {
dp[u] = -(S[u] - '0');
for(auto v : adj[u]) if (v != p) {
gen(v, u);
dp[u] += max(dp[v], on[v]);
}
// cout << u << " " << max(dp[u], on[u]) << nl;
};
gen(0, -1);
int ans = 0;
function<void(int, int)> dfs = [&](int u, int p) {
// cout << u << " " << dp[u] << nl;
ans = max(ans, max(dp[u], on[u]));
for(auto v : adj[u]) if (v != p) {
ans = max(ans, max(dp[v], on[v]) + on[u]);
dp[u] -= max(dp[v], on[v]);
dp[v] += max(dp[u], on[u]);
dfs(v, u);
dp[v] -= max(dp[u], on[u]);
dp[u] += max(dp[v], on[v]);
}
};
dfs(0, -1);
cout << ans << nl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
596 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
2 ms |
340 KB |
Output is correct |
36 |
Correct |
2 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
468 KB |
Output is correct |
40 |
Correct |
1 ms |
468 KB |
Output is correct |
41 |
Correct |
1 ms |
468 KB |
Output is correct |
42 |
Correct |
1 ms |
468 KB |
Output is correct |
43 |
Correct |
1 ms |
468 KB |
Output is correct |
44 |
Correct |
1 ms |
468 KB |
Output is correct |
45 |
Correct |
1 ms |
468 KB |
Output is correct |
46 |
Correct |
1 ms |
468 KB |
Output is correct |
47 |
Correct |
1 ms |
468 KB |
Output is correct |
48 |
Correct |
1 ms |
468 KB |
Output is correct |
49 |
Correct |
1 ms |
468 KB |
Output is correct |
50 |
Correct |
1 ms |
468 KB |
Output is correct |
51 |
Correct |
1 ms |
468 KB |
Output is correct |
52 |
Correct |
1 ms |
340 KB |
Output is correct |
53 |
Correct |
1 ms |
468 KB |
Output is correct |
54 |
Correct |
1 ms |
468 KB |
Output is correct |
55 |
Correct |
1 ms |
468 KB |
Output is correct |
56 |
Correct |
1 ms |
340 KB |
Output is correct |
57 |
Correct |
1 ms |
596 KB |
Output is correct |
58 |
Correct |
1 ms |
340 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
1 ms |
468 KB |
Output is correct |
61 |
Correct |
1 ms |
340 KB |
Output is correct |
62 |
Correct |
2 ms |
468 KB |
Output is correct |
63 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
596 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
2 ms |
340 KB |
Output is correct |
36 |
Correct |
2 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
468 KB |
Output is correct |
40 |
Correct |
1 ms |
468 KB |
Output is correct |
41 |
Correct |
1 ms |
468 KB |
Output is correct |
42 |
Correct |
1 ms |
468 KB |
Output is correct |
43 |
Correct |
1 ms |
468 KB |
Output is correct |
44 |
Correct |
1 ms |
468 KB |
Output is correct |
45 |
Correct |
1 ms |
468 KB |
Output is correct |
46 |
Correct |
1 ms |
468 KB |
Output is correct |
47 |
Correct |
1 ms |
468 KB |
Output is correct |
48 |
Correct |
1 ms |
468 KB |
Output is correct |
49 |
Correct |
1 ms |
468 KB |
Output is correct |
50 |
Correct |
1 ms |
468 KB |
Output is correct |
51 |
Correct |
1 ms |
468 KB |
Output is correct |
52 |
Correct |
1 ms |
340 KB |
Output is correct |
53 |
Correct |
1 ms |
468 KB |
Output is correct |
54 |
Correct |
1 ms |
468 KB |
Output is correct |
55 |
Correct |
1 ms |
468 KB |
Output is correct |
56 |
Correct |
1 ms |
340 KB |
Output is correct |
57 |
Correct |
1 ms |
596 KB |
Output is correct |
58 |
Correct |
1 ms |
340 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
1 ms |
468 KB |
Output is correct |
61 |
Correct |
1 ms |
340 KB |
Output is correct |
62 |
Correct |
2 ms |
468 KB |
Output is correct |
63 |
Correct |
1 ms |
340 KB |
Output is correct |
64 |
Correct |
150 ms |
13164 KB |
Output is correct |
65 |
Correct |
132 ms |
13292 KB |
Output is correct |
66 |
Correct |
159 ms |
13272 KB |
Output is correct |
67 |
Correct |
177 ms |
13272 KB |
Output is correct |
68 |
Correct |
143 ms |
13280 KB |
Output is correct |
69 |
Correct |
152 ms |
13172 KB |
Output is correct |
70 |
Correct |
144 ms |
13296 KB |
Output is correct |
71 |
Correct |
161 ms |
13276 KB |
Output is correct |
72 |
Correct |
145 ms |
13196 KB |
Output is correct |
73 |
Correct |
158 ms |
28404 KB |
Output is correct |
74 |
Correct |
167 ms |
28364 KB |
Output is correct |
75 |
Correct |
144 ms |
13128 KB |
Output is correct |
76 |
Correct |
137 ms |
13172 KB |
Output is correct |
77 |
Correct |
151 ms |
13056 KB |
Output is correct |
78 |
Correct |
161 ms |
13128 KB |
Output is correct |
79 |
Correct |
151 ms |
13168 KB |
Output is correct |
80 |
Correct |
142 ms |
13056 KB |
Output is correct |
81 |
Correct |
122 ms |
13656 KB |
Output is correct |
82 |
Correct |
161 ms |
13332 KB |
Output is correct |
83 |
Correct |
163 ms |
19320 KB |
Output is correct |
84 |
Correct |
158 ms |
21980 KB |
Output is correct |
85 |
Correct |
161 ms |
21540 KB |
Output is correct |
86 |
Correct |
140 ms |
14988 KB |
Output is correct |
87 |
Correct |
155 ms |
14192 KB |
Output is correct |
88 |
Correct |
137 ms |
14576 KB |
Output is correct |
89 |
Correct |
147 ms |
14588 KB |
Output is correct |
90 |
Correct |
144 ms |
14316 KB |
Output is correct |
91 |
Correct |
149 ms |
14676 KB |
Output is correct |
92 |
Correct |
177 ms |
14996 KB |
Output is correct |
93 |
Correct |
135 ms |
18016 KB |
Output is correct |
94 |
Correct |
132 ms |
20152 KB |
Output is correct |
95 |
Correct |
138 ms |
18460 KB |
Output is correct |
96 |
Correct |
137 ms |
16288 KB |
Output is correct |
97 |
Correct |
140 ms |
14432 KB |
Output is correct |
98 |
Correct |
146 ms |
13768 KB |
Output is correct |
99 |
Correct |
148 ms |
13632 KB |
Output is correct |
100 |
Correct |
139 ms |
17540 KB |
Output is correct |
101 |
Correct |
140 ms |
15052 KB |
Output is correct |
102 |
Correct |
127 ms |
14036 KB |
Output is correct |
103 |
Correct |
132 ms |
13740 KB |
Output is correct |
104 |
Correct |
72 ms |
14044 KB |
Output is correct |
105 |
Correct |
167 ms |
24684 KB |
Output is correct |
106 |
Correct |
73 ms |
14204 KB |
Output is correct |
107 |
Correct |
71 ms |
13996 KB |
Output is correct |
108 |
Correct |
166 ms |
29232 KB |
Output is correct |
109 |
Correct |
71 ms |
14024 KB |
Output is correct |
110 |
Correct |
166 ms |
29632 KB |
Output is correct |
111 |
Correct |
136 ms |
13220 KB |
Output is correct |