# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
959140 |
2024-04-07T14:12:20 Z |
Pring |
Power Plant (JOI20_power) |
C++17 |
|
583 ms |
26108 KB |
#include <bits/stdc++.h>
using namespace std;
#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
typedef pair<int, int> pii;
const int MXN = 200005;
int n;
vector<int> edge[MXN];
string s;
int sz[MXN], ans;
bitset<MXN> ban;
void GET_SZ(int id, int par) {
sz[id] = 1;
for (auto &i : edge[id]) {
if (i == par) continue;
if (ban[i]) continue;
GET_SZ(i, id);
sz[id] += sz[i];
}
}
int GET_CD(int id, int par, int S) {
for (auto &i : edge[id]) {
if (i == par) continue;
if (ban[i]) continue;
if (sz[i] > S / 2) return GET_CD(i, id, S);
}
return id;
}
int DP(int id, int par) {
int ans = ((s[id] & 1) ? -1 : 0);
for (auto &i : edge[id]) {
if (i == par) continue;
if (ban[i]) continue;
ans += DP(i, id);
}
if (s[id] & 1) ans = max(ans, 1);
return ans;
}
int calc(int id) {
int now = 0, cnt = 0, big = 0;
for (auto &i : edge[id]) {
if (ban[i]) continue;
int x = DP(i, id);
now += x;
big = max(big, x);
if (x) cnt++;
}
if (cnt == 0) return (s[id] & 1);
if (cnt == 1) return now + (s[id] & 1);
if (s[id] & 1) return max(1 + big, now - 1);
return now;
}
void CD(int id) {
GET_SZ(id, 0);
int ct = GET_CD(id, 0, sz[id]);
ans = max(ans, calc(ct));
ban[ct] = true;
for (auto &i : edge[ct]) {
if (ban[i]) continue;
CD(i);
}
}
void miku() {
int x, y;
cin >> n;
FOR(i, 1, n) {
cin >> x >> y;
edge[x].push_back(y);
edge[y].push_back(x);
}
cin >> s;
s = " " + s;
CD(1);
cout << ans << '\n';
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(false);
cin.exceptions(cin.failbit);
miku();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5724 KB |
Output is correct |
2 |
Correct |
1 ms |
5724 KB |
Output is correct |
3 |
Correct |
2 ms |
5976 KB |
Output is correct |
4 |
Correct |
2 ms |
5724 KB |
Output is correct |
5 |
Correct |
1 ms |
5724 KB |
Output is correct |
6 |
Correct |
2 ms |
5720 KB |
Output is correct |
7 |
Correct |
2 ms |
5724 KB |
Output is correct |
8 |
Correct |
2 ms |
5724 KB |
Output is correct |
9 |
Correct |
2 ms |
5724 KB |
Output is correct |
10 |
Correct |
2 ms |
5724 KB |
Output is correct |
11 |
Correct |
2 ms |
5720 KB |
Output is correct |
12 |
Correct |
2 ms |
5724 KB |
Output is correct |
13 |
Correct |
2 ms |
5720 KB |
Output is correct |
14 |
Correct |
1 ms |
5724 KB |
Output is correct |
15 |
Correct |
2 ms |
5724 KB |
Output is correct |
16 |
Correct |
2 ms |
5724 KB |
Output is correct |
17 |
Correct |
2 ms |
5720 KB |
Output is correct |
18 |
Correct |
2 ms |
5724 KB |
Output is correct |
19 |
Correct |
2 ms |
5724 KB |
Output is correct |
20 |
Correct |
2 ms |
5724 KB |
Output is correct |
21 |
Correct |
2 ms |
5788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5724 KB |
Output is correct |
2 |
Correct |
1 ms |
5724 KB |
Output is correct |
3 |
Correct |
2 ms |
5976 KB |
Output is correct |
4 |
Correct |
2 ms |
5724 KB |
Output is correct |
5 |
Correct |
1 ms |
5724 KB |
Output is correct |
6 |
Correct |
2 ms |
5720 KB |
Output is correct |
7 |
Correct |
2 ms |
5724 KB |
Output is correct |
8 |
Correct |
2 ms |
5724 KB |
Output is correct |
9 |
Correct |
2 ms |
5724 KB |
Output is correct |
10 |
Correct |
2 ms |
5724 KB |
Output is correct |
11 |
Correct |
2 ms |
5720 KB |
Output is correct |
12 |
Correct |
2 ms |
5724 KB |
Output is correct |
13 |
Correct |
2 ms |
5720 KB |
Output is correct |
14 |
Correct |
1 ms |
5724 KB |
Output is correct |
15 |
Correct |
2 ms |
5724 KB |
Output is correct |
16 |
Correct |
2 ms |
5724 KB |
Output is correct |
17 |
Correct |
2 ms |
5720 KB |
Output is correct |
18 |
Correct |
2 ms |
5724 KB |
Output is correct |
19 |
Correct |
2 ms |
5724 KB |
Output is correct |
20 |
Correct |
2 ms |
5724 KB |
Output is correct |
21 |
Correct |
2 ms |
5788 KB |
Output is correct |
22 |
Correct |
3 ms |
5724 KB |
Output is correct |
23 |
Correct |
3 ms |
5724 KB |
Output is correct |
24 |
Correct |
3 ms |
5724 KB |
Output is correct |
25 |
Correct |
3 ms |
5800 KB |
Output is correct |
26 |
Correct |
3 ms |
5724 KB |
Output is correct |
27 |
Correct |
3 ms |
5724 KB |
Output is correct |
28 |
Correct |
3 ms |
5724 KB |
Output is correct |
29 |
Correct |
3 ms |
5980 KB |
Output is correct |
30 |
Correct |
3 ms |
5724 KB |
Output is correct |
31 |
Correct |
2 ms |
5724 KB |
Output is correct |
32 |
Correct |
3 ms |
5724 KB |
Output is correct |
33 |
Correct |
3 ms |
5724 KB |
Output is correct |
34 |
Correct |
3 ms |
5720 KB |
Output is correct |
35 |
Correct |
2 ms |
5724 KB |
Output is correct |
36 |
Correct |
2 ms |
5664 KB |
Output is correct |
37 |
Correct |
2 ms |
5976 KB |
Output is correct |
38 |
Correct |
2 ms |
5724 KB |
Output is correct |
39 |
Correct |
3 ms |
5724 KB |
Output is correct |
40 |
Correct |
3 ms |
5920 KB |
Output is correct |
41 |
Correct |
3 ms |
5820 KB |
Output is correct |
42 |
Correct |
3 ms |
5804 KB |
Output is correct |
43 |
Correct |
3 ms |
5808 KB |
Output is correct |
44 |
Correct |
2 ms |
5724 KB |
Output is correct |
45 |
Correct |
3 ms |
5980 KB |
Output is correct |
46 |
Correct |
4 ms |
5724 KB |
Output is correct |
47 |
Correct |
2 ms |
5724 KB |
Output is correct |
48 |
Correct |
2 ms |
5724 KB |
Output is correct |
49 |
Correct |
2 ms |
5880 KB |
Output is correct |
50 |
Correct |
3 ms |
5724 KB |
Output is correct |
51 |
Correct |
2 ms |
5800 KB |
Output is correct |
52 |
Correct |
2 ms |
5724 KB |
Output is correct |
53 |
Correct |
2 ms |
5720 KB |
Output is correct |
54 |
Correct |
2 ms |
5724 KB |
Output is correct |
55 |
Correct |
2 ms |
5720 KB |
Output is correct |
56 |
Correct |
2 ms |
5724 KB |
Output is correct |
57 |
Correct |
3 ms |
5808 KB |
Output is correct |
58 |
Correct |
2 ms |
5724 KB |
Output is correct |
59 |
Correct |
3 ms |
5800 KB |
Output is correct |
60 |
Correct |
4 ms |
5980 KB |
Output is correct |
61 |
Correct |
2 ms |
5720 KB |
Output is correct |
62 |
Correct |
3 ms |
5724 KB |
Output is correct |
63 |
Correct |
2 ms |
5724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5724 KB |
Output is correct |
2 |
Correct |
1 ms |
5724 KB |
Output is correct |
3 |
Correct |
2 ms |
5976 KB |
Output is correct |
4 |
Correct |
2 ms |
5724 KB |
Output is correct |
5 |
Correct |
1 ms |
5724 KB |
Output is correct |
6 |
Correct |
2 ms |
5720 KB |
Output is correct |
7 |
Correct |
2 ms |
5724 KB |
Output is correct |
8 |
Correct |
2 ms |
5724 KB |
Output is correct |
9 |
Correct |
2 ms |
5724 KB |
Output is correct |
10 |
Correct |
2 ms |
5724 KB |
Output is correct |
11 |
Correct |
2 ms |
5720 KB |
Output is correct |
12 |
Correct |
2 ms |
5724 KB |
Output is correct |
13 |
Correct |
2 ms |
5720 KB |
Output is correct |
14 |
Correct |
1 ms |
5724 KB |
Output is correct |
15 |
Correct |
2 ms |
5724 KB |
Output is correct |
16 |
Correct |
2 ms |
5724 KB |
Output is correct |
17 |
Correct |
2 ms |
5720 KB |
Output is correct |
18 |
Correct |
2 ms |
5724 KB |
Output is correct |
19 |
Correct |
2 ms |
5724 KB |
Output is correct |
20 |
Correct |
2 ms |
5724 KB |
Output is correct |
21 |
Correct |
2 ms |
5788 KB |
Output is correct |
22 |
Correct |
3 ms |
5724 KB |
Output is correct |
23 |
Correct |
3 ms |
5724 KB |
Output is correct |
24 |
Correct |
3 ms |
5724 KB |
Output is correct |
25 |
Correct |
3 ms |
5800 KB |
Output is correct |
26 |
Correct |
3 ms |
5724 KB |
Output is correct |
27 |
Correct |
3 ms |
5724 KB |
Output is correct |
28 |
Correct |
3 ms |
5724 KB |
Output is correct |
29 |
Correct |
3 ms |
5980 KB |
Output is correct |
30 |
Correct |
3 ms |
5724 KB |
Output is correct |
31 |
Correct |
2 ms |
5724 KB |
Output is correct |
32 |
Correct |
3 ms |
5724 KB |
Output is correct |
33 |
Correct |
3 ms |
5724 KB |
Output is correct |
34 |
Correct |
3 ms |
5720 KB |
Output is correct |
35 |
Correct |
2 ms |
5724 KB |
Output is correct |
36 |
Correct |
2 ms |
5664 KB |
Output is correct |
37 |
Correct |
2 ms |
5976 KB |
Output is correct |
38 |
Correct |
2 ms |
5724 KB |
Output is correct |
39 |
Correct |
3 ms |
5724 KB |
Output is correct |
40 |
Correct |
3 ms |
5920 KB |
Output is correct |
41 |
Correct |
3 ms |
5820 KB |
Output is correct |
42 |
Correct |
3 ms |
5804 KB |
Output is correct |
43 |
Correct |
3 ms |
5808 KB |
Output is correct |
44 |
Correct |
2 ms |
5724 KB |
Output is correct |
45 |
Correct |
3 ms |
5980 KB |
Output is correct |
46 |
Correct |
4 ms |
5724 KB |
Output is correct |
47 |
Correct |
2 ms |
5724 KB |
Output is correct |
48 |
Correct |
2 ms |
5724 KB |
Output is correct |
49 |
Correct |
2 ms |
5880 KB |
Output is correct |
50 |
Correct |
3 ms |
5724 KB |
Output is correct |
51 |
Correct |
2 ms |
5800 KB |
Output is correct |
52 |
Correct |
2 ms |
5724 KB |
Output is correct |
53 |
Correct |
2 ms |
5720 KB |
Output is correct |
54 |
Correct |
2 ms |
5724 KB |
Output is correct |
55 |
Correct |
2 ms |
5720 KB |
Output is correct |
56 |
Correct |
2 ms |
5724 KB |
Output is correct |
57 |
Correct |
3 ms |
5808 KB |
Output is correct |
58 |
Correct |
2 ms |
5724 KB |
Output is correct |
59 |
Correct |
3 ms |
5800 KB |
Output is correct |
60 |
Correct |
4 ms |
5980 KB |
Output is correct |
61 |
Correct |
2 ms |
5720 KB |
Output is correct |
62 |
Correct |
3 ms |
5724 KB |
Output is correct |
63 |
Correct |
2 ms |
5724 KB |
Output is correct |
64 |
Correct |
225 ms |
15248 KB |
Output is correct |
65 |
Correct |
312 ms |
15308 KB |
Output is correct |
66 |
Correct |
247 ms |
15220 KB |
Output is correct |
67 |
Correct |
264 ms |
15340 KB |
Output is correct |
68 |
Correct |
214 ms |
15288 KB |
Output is correct |
69 |
Correct |
216 ms |
15260 KB |
Output is correct |
70 |
Correct |
218 ms |
15336 KB |
Output is correct |
71 |
Correct |
208 ms |
15320 KB |
Output is correct |
72 |
Correct |
293 ms |
15348 KB |
Output is correct |
73 |
Correct |
464 ms |
25300 KB |
Output is correct |
74 |
Correct |
469 ms |
25288 KB |
Output is correct |
75 |
Correct |
222 ms |
15248 KB |
Output is correct |
76 |
Correct |
198 ms |
15248 KB |
Output is correct |
77 |
Correct |
251 ms |
15244 KB |
Output is correct |
78 |
Correct |
221 ms |
15248 KB |
Output is correct |
79 |
Correct |
252 ms |
15264 KB |
Output is correct |
80 |
Correct |
294 ms |
15244 KB |
Output is correct |
81 |
Correct |
79 ms |
15672 KB |
Output is correct |
82 |
Correct |
106 ms |
15440 KB |
Output is correct |
83 |
Correct |
330 ms |
19408 KB |
Output is correct |
84 |
Correct |
343 ms |
21132 KB |
Output is correct |
85 |
Correct |
401 ms |
20928 KB |
Output is correct |
86 |
Correct |
264 ms |
16592 KB |
Output is correct |
87 |
Correct |
287 ms |
15968 KB |
Output is correct |
88 |
Correct |
218 ms |
16440 KB |
Output is correct |
89 |
Correct |
260 ms |
16344 KB |
Output is correct |
90 |
Correct |
196 ms |
16396 KB |
Output is correct |
91 |
Correct |
206 ms |
16372 KB |
Output is correct |
92 |
Correct |
248 ms |
16736 KB |
Output is correct |
93 |
Correct |
232 ms |
21152 KB |
Output is correct |
94 |
Correct |
211 ms |
22476 KB |
Output is correct |
95 |
Correct |
223 ms |
19080 KB |
Output is correct |
96 |
Correct |
235 ms |
17720 KB |
Output is correct |
97 |
Correct |
158 ms |
16196 KB |
Output is correct |
98 |
Correct |
144 ms |
15872 KB |
Output is correct |
99 |
Correct |
220 ms |
15684 KB |
Output is correct |
100 |
Correct |
191 ms |
18084 KB |
Output is correct |
101 |
Correct |
196 ms |
16560 KB |
Output is correct |
102 |
Correct |
183 ms |
16028 KB |
Output is correct |
103 |
Correct |
198 ms |
16032 KB |
Output is correct |
104 |
Correct |
48 ms |
16072 KB |
Output is correct |
105 |
Correct |
418 ms |
23228 KB |
Output is correct |
106 |
Correct |
59 ms |
16040 KB |
Output is correct |
107 |
Correct |
54 ms |
16104 KB |
Output is correct |
108 |
Correct |
438 ms |
26092 KB |
Output is correct |
109 |
Correct |
48 ms |
16208 KB |
Output is correct |
110 |
Correct |
583 ms |
26108 KB |
Output is correct |
111 |
Correct |
142 ms |
15268 KB |
Output is correct |