# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1031872 |
2024-07-23T08:17:44 Z |
변재우(#10964) |
Power Plant (JOI20_power) |
C++17 |
|
90 ms |
26328 KB |
#include <bits/stdc++.h>
using namespace std;
const int Nmax=200010;
int N, ans, D1[Nmax], D2[Nmax];
bool A[Nmax];
string S;
vector<int> adj[Nmax];
void DFS(int curr, int prev) {
for(int next:adj[curr]) if(next!=prev) DFS(next, curr);
if(!A[curr]) {
for(int next:adj[curr]) if(next!=prev) D1[curr]+=D1[next];
}
else {
for(int next:adj[curr]) if(next!=prev) D1[curr]+=D1[next];
D1[curr]=max(1, D1[curr]-1);
for(int next:adj[curr]) if(next!=prev) D2[curr]+=D1[next];
D2[curr]--;
int tmp=0;
for(int next:adj[curr]) if(next!=prev) tmp=max(tmp, D1[next]);
D2[curr]=max(D2[curr], tmp+1);
}
ans=max({ans, D1[curr], D2[curr]});
}
signed 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;
for(int i=1; i<=N; i++) A[i]=S[i-1]-'0';
DFS(1, 0);
cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
3 ms |
4956 KB |
Output is correct |
3 |
Correct |
3 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
5172 KB |
Output is correct |
6 |
Correct |
3 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
5156 KB |
Output is correct |
9 |
Correct |
3 ms |
4956 KB |
Output is correct |
10 |
Correct |
3 ms |
4944 KB |
Output is correct |
11 |
Correct |
2 ms |
5176 KB |
Output is correct |
12 |
Correct |
2 ms |
5092 KB |
Output is correct |
13 |
Correct |
3 ms |
5052 KB |
Output is correct |
14 |
Correct |
3 ms |
5172 KB |
Output is correct |
15 |
Correct |
2 ms |
4956 KB |
Output is correct |
16 |
Correct |
3 ms |
4956 KB |
Output is correct |
17 |
Correct |
3 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
5144 KB |
Output is correct |
20 |
Correct |
2 ms |
5168 KB |
Output is correct |
21 |
Correct |
2 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
3 ms |
4956 KB |
Output is correct |
3 |
Correct |
3 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
5172 KB |
Output is correct |
6 |
Correct |
3 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
5156 KB |
Output is correct |
9 |
Correct |
3 ms |
4956 KB |
Output is correct |
10 |
Correct |
3 ms |
4944 KB |
Output is correct |
11 |
Correct |
2 ms |
5176 KB |
Output is correct |
12 |
Correct |
2 ms |
5092 KB |
Output is correct |
13 |
Correct |
3 ms |
5052 KB |
Output is correct |
14 |
Correct |
3 ms |
5172 KB |
Output is correct |
15 |
Correct |
2 ms |
4956 KB |
Output is correct |
16 |
Correct |
3 ms |
4956 KB |
Output is correct |
17 |
Correct |
3 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
5144 KB |
Output is correct |
20 |
Correct |
2 ms |
5168 KB |
Output is correct |
21 |
Correct |
2 ms |
4956 KB |
Output is correct |
22 |
Correct |
3 ms |
5212 KB |
Output is correct |
23 |
Correct |
3 ms |
5212 KB |
Output is correct |
24 |
Correct |
3 ms |
5208 KB |
Output is correct |
25 |
Correct |
3 ms |
5212 KB |
Output is correct |
26 |
Correct |
3 ms |
5208 KB |
Output is correct |
27 |
Correct |
4 ms |
5212 KB |
Output is correct |
28 |
Correct |
3 ms |
5180 KB |
Output is correct |
29 |
Correct |
3 ms |
5216 KB |
Output is correct |
30 |
Correct |
3 ms |
5224 KB |
Output is correct |
31 |
Correct |
3 ms |
5220 KB |
Output is correct |
32 |
Correct |
4 ms |
5220 KB |
Output is correct |
33 |
Correct |
2 ms |
5224 KB |
Output is correct |
34 |
Correct |
3 ms |
5180 KB |
Output is correct |
35 |
Correct |
2 ms |
5224 KB |
Output is correct |
36 |
Correct |
3 ms |
5216 KB |
Output is correct |
37 |
Correct |
2 ms |
5220 KB |
Output is correct |
38 |
Correct |
4 ms |
5268 KB |
Output is correct |
39 |
Correct |
3 ms |
5216 KB |
Output is correct |
40 |
Correct |
3 ms |
5168 KB |
Output is correct |
41 |
Correct |
3 ms |
5212 KB |
Output is correct |
42 |
Correct |
2 ms |
5184 KB |
Output is correct |
43 |
Correct |
3 ms |
5180 KB |
Output is correct |
44 |
Correct |
3 ms |
5260 KB |
Output is correct |
45 |
Correct |
3 ms |
5252 KB |
Output is correct |
46 |
Correct |
2 ms |
5212 KB |
Output is correct |
47 |
Correct |
2 ms |
5212 KB |
Output is correct |
48 |
Correct |
3 ms |
5216 KB |
Output is correct |
49 |
Correct |
3 ms |
5224 KB |
Output is correct |
50 |
Correct |
3 ms |
5224 KB |
Output is correct |
51 |
Correct |
3 ms |
5224 KB |
Output is correct |
52 |
Correct |
3 ms |
5224 KB |
Output is correct |
53 |
Correct |
2 ms |
5268 KB |
Output is correct |
54 |
Correct |
4 ms |
5224 KB |
Output is correct |
55 |
Correct |
3 ms |
5224 KB |
Output is correct |
56 |
Correct |
4 ms |
5224 KB |
Output is correct |
57 |
Correct |
3 ms |
5224 KB |
Output is correct |
58 |
Correct |
3 ms |
5212 KB |
Output is correct |
59 |
Correct |
2 ms |
5212 KB |
Output is correct |
60 |
Correct |
3 ms |
5208 KB |
Output is correct |
61 |
Correct |
2 ms |
5212 KB |
Output is correct |
62 |
Correct |
3 ms |
5212 KB |
Output is correct |
63 |
Correct |
3 ms |
5268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
3 ms |
4956 KB |
Output is correct |
3 |
Correct |
3 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
5172 KB |
Output is correct |
6 |
Correct |
3 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
5156 KB |
Output is correct |
9 |
Correct |
3 ms |
4956 KB |
Output is correct |
10 |
Correct |
3 ms |
4944 KB |
Output is correct |
11 |
Correct |
2 ms |
5176 KB |
Output is correct |
12 |
Correct |
2 ms |
5092 KB |
Output is correct |
13 |
Correct |
3 ms |
5052 KB |
Output is correct |
14 |
Correct |
3 ms |
5172 KB |
Output is correct |
15 |
Correct |
2 ms |
4956 KB |
Output is correct |
16 |
Correct |
3 ms |
4956 KB |
Output is correct |
17 |
Correct |
3 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
5144 KB |
Output is correct |
20 |
Correct |
2 ms |
5168 KB |
Output is correct |
21 |
Correct |
2 ms |
4956 KB |
Output is correct |
22 |
Correct |
3 ms |
5212 KB |
Output is correct |
23 |
Correct |
3 ms |
5212 KB |
Output is correct |
24 |
Correct |
3 ms |
5208 KB |
Output is correct |
25 |
Correct |
3 ms |
5212 KB |
Output is correct |
26 |
Correct |
3 ms |
5208 KB |
Output is correct |
27 |
Correct |
4 ms |
5212 KB |
Output is correct |
28 |
Correct |
3 ms |
5180 KB |
Output is correct |
29 |
Correct |
3 ms |
5216 KB |
Output is correct |
30 |
Correct |
3 ms |
5224 KB |
Output is correct |
31 |
Correct |
3 ms |
5220 KB |
Output is correct |
32 |
Correct |
4 ms |
5220 KB |
Output is correct |
33 |
Correct |
2 ms |
5224 KB |
Output is correct |
34 |
Correct |
3 ms |
5180 KB |
Output is correct |
35 |
Correct |
2 ms |
5224 KB |
Output is correct |
36 |
Correct |
3 ms |
5216 KB |
Output is correct |
37 |
Correct |
2 ms |
5220 KB |
Output is correct |
38 |
Correct |
4 ms |
5268 KB |
Output is correct |
39 |
Correct |
3 ms |
5216 KB |
Output is correct |
40 |
Correct |
3 ms |
5168 KB |
Output is correct |
41 |
Correct |
3 ms |
5212 KB |
Output is correct |
42 |
Correct |
2 ms |
5184 KB |
Output is correct |
43 |
Correct |
3 ms |
5180 KB |
Output is correct |
44 |
Correct |
3 ms |
5260 KB |
Output is correct |
45 |
Correct |
3 ms |
5252 KB |
Output is correct |
46 |
Correct |
2 ms |
5212 KB |
Output is correct |
47 |
Correct |
2 ms |
5212 KB |
Output is correct |
48 |
Correct |
3 ms |
5216 KB |
Output is correct |
49 |
Correct |
3 ms |
5224 KB |
Output is correct |
50 |
Correct |
3 ms |
5224 KB |
Output is correct |
51 |
Correct |
3 ms |
5224 KB |
Output is correct |
52 |
Correct |
3 ms |
5224 KB |
Output is correct |
53 |
Correct |
2 ms |
5268 KB |
Output is correct |
54 |
Correct |
4 ms |
5224 KB |
Output is correct |
55 |
Correct |
3 ms |
5224 KB |
Output is correct |
56 |
Correct |
4 ms |
5224 KB |
Output is correct |
57 |
Correct |
3 ms |
5224 KB |
Output is correct |
58 |
Correct |
3 ms |
5212 KB |
Output is correct |
59 |
Correct |
2 ms |
5212 KB |
Output is correct |
60 |
Correct |
3 ms |
5208 KB |
Output is correct |
61 |
Correct |
2 ms |
5212 KB |
Output is correct |
62 |
Correct |
3 ms |
5212 KB |
Output is correct |
63 |
Correct |
3 ms |
5268 KB |
Output is correct |
64 |
Correct |
58 ms |
16280 KB |
Output is correct |
65 |
Correct |
75 ms |
16272 KB |
Output is correct |
66 |
Correct |
87 ms |
16252 KB |
Output is correct |
67 |
Correct |
62 ms |
16288 KB |
Output is correct |
68 |
Correct |
62 ms |
16208 KB |
Output is correct |
69 |
Correct |
57 ms |
16268 KB |
Output is correct |
70 |
Correct |
62 ms |
16292 KB |
Output is correct |
71 |
Correct |
55 ms |
16284 KB |
Output is correct |
72 |
Correct |
59 ms |
15492 KB |
Output is correct |
73 |
Correct |
74 ms |
26260 KB |
Output is correct |
74 |
Correct |
72 ms |
26328 KB |
Output is correct |
75 |
Correct |
55 ms |
16020 KB |
Output is correct |
76 |
Correct |
66 ms |
16012 KB |
Output is correct |
77 |
Correct |
82 ms |
16016 KB |
Output is correct |
78 |
Correct |
62 ms |
16020 KB |
Output is correct |
79 |
Correct |
71 ms |
16028 KB |
Output is correct |
80 |
Correct |
58 ms |
16016 KB |
Output is correct |
81 |
Correct |
58 ms |
16584 KB |
Output is correct |
82 |
Correct |
59 ms |
16212 KB |
Output is correct |
83 |
Correct |
63 ms |
20376 KB |
Output is correct |
84 |
Correct |
64 ms |
21876 KB |
Output is correct |
85 |
Correct |
79 ms |
21664 KB |
Output is correct |
86 |
Correct |
64 ms |
17164 KB |
Output is correct |
87 |
Correct |
55 ms |
16780 KB |
Output is correct |
88 |
Correct |
89 ms |
17360 KB |
Output is correct |
89 |
Correct |
60 ms |
17372 KB |
Output is correct |
90 |
Correct |
58 ms |
17100 KB |
Output is correct |
91 |
Correct |
84 ms |
17216 KB |
Output is correct |
92 |
Correct |
56 ms |
17488 KB |
Output is correct |
93 |
Correct |
79 ms |
19512 KB |
Output is correct |
94 |
Correct |
86 ms |
20896 KB |
Output is correct |
95 |
Correct |
58 ms |
19784 KB |
Output is correct |
96 |
Correct |
71 ms |
18344 KB |
Output is correct |
97 |
Correct |
66 ms |
17048 KB |
Output is correct |
98 |
Correct |
57 ms |
16744 KB |
Output is correct |
99 |
Correct |
61 ms |
16524 KB |
Output is correct |
100 |
Correct |
63 ms |
19000 KB |
Output is correct |
101 |
Correct |
68 ms |
17420 KB |
Output is correct |
102 |
Correct |
53 ms |
16796 KB |
Output is correct |
103 |
Correct |
68 ms |
16772 KB |
Output is correct |
104 |
Correct |
46 ms |
15548 KB |
Output is correct |
105 |
Correct |
77 ms |
22968 KB |
Output is correct |
106 |
Correct |
63 ms |
16944 KB |
Output is correct |
107 |
Correct |
48 ms |
16988 KB |
Output is correct |
108 |
Correct |
90 ms |
26004 KB |
Output is correct |
109 |
Correct |
43 ms |
15556 KB |
Output is correct |
110 |
Correct |
73 ms |
26256 KB |
Output is correct |
111 |
Correct |
56 ms |
16028 KB |
Output is correct |