# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
885796 |
2023-12-10T18:44:39 Z |
wksp |
Power Plant (JOI20_power) |
C++14 |
|
120 ms |
28724 KB |
#include<bits/stdc++.h>
using namespace std;
const int n_max = 2 * 1e5 + 7;
vector<int> graph[n_max];
int power_generator[n_max];
int ans;
int DFS(int v, int p){
int sum = 0;
int max_vallue = 0;
for(auto u: graph[v]){
if(u != p){
int vallue = DFS(u ,v);
sum += vallue;
max_vallue = max(max_vallue, vallue);
}
}
int ans_tym = 0;
if(power_generator[v] == 1){
ans_tym = max(sum - 1, 1);
if(sum == max_vallue){
ans = max(ans, sum + 1);
}
if(sum == max_vallue + 1){
ans = max(ans, sum);
}
}else{
ans_tym = sum;
}
ans = max(ans, ans_tym);
return ans_tym;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
ans = 0;
int n;
cin >> n;
for(int i = 0; i < n - 1; i++){
int a, b;
cin >> a >> b;
graph[a].push_back(b);
graph[b].push_back(a);
}
string s;
cin >> s;
for(int i = 0; i < n; i++){
if(s[i] == '1'){
power_generator[i+1] = 1;
}
}
ans = 0;
DFS(1, 0);
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5724 KB |
Output is correct |
2 |
Correct |
2 ms |
5980 KB |
Output is correct |
3 |
Correct |
2 ms |
5720 KB |
Output is correct |
4 |
Correct |
1 ms |
5724 KB |
Output is correct |
5 |
Correct |
1 ms |
5760 KB |
Output is correct |
6 |
Correct |
1 ms |
5724 KB |
Output is correct |
7 |
Correct |
1 ms |
5724 KB |
Output is correct |
8 |
Correct |
1 ms |
5724 KB |
Output is correct |
9 |
Correct |
1 ms |
5724 KB |
Output is correct |
10 |
Correct |
1 ms |
5648 KB |
Output is correct |
11 |
Correct |
2 ms |
5724 KB |
Output is correct |
12 |
Correct |
1 ms |
5720 KB |
Output is correct |
13 |
Correct |
1 ms |
5724 KB |
Output is correct |
14 |
Correct |
1 ms |
5724 KB |
Output is correct |
15 |
Correct |
1 ms |
5724 KB |
Output is correct |
16 |
Correct |
1 ms |
5724 KB |
Output is correct |
17 |
Correct |
2 ms |
5720 KB |
Output is correct |
18 |
Correct |
2 ms |
5720 KB |
Output is correct |
19 |
Correct |
2 ms |
5724 KB |
Output is correct |
20 |
Correct |
1 ms |
5724 KB |
Output is correct |
21 |
Correct |
2 ms |
5724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5724 KB |
Output is correct |
2 |
Correct |
2 ms |
5980 KB |
Output is correct |
3 |
Correct |
2 ms |
5720 KB |
Output is correct |
4 |
Correct |
1 ms |
5724 KB |
Output is correct |
5 |
Correct |
1 ms |
5760 KB |
Output is correct |
6 |
Correct |
1 ms |
5724 KB |
Output is correct |
7 |
Correct |
1 ms |
5724 KB |
Output is correct |
8 |
Correct |
1 ms |
5724 KB |
Output is correct |
9 |
Correct |
1 ms |
5724 KB |
Output is correct |
10 |
Correct |
1 ms |
5648 KB |
Output is correct |
11 |
Correct |
2 ms |
5724 KB |
Output is correct |
12 |
Correct |
1 ms |
5720 KB |
Output is correct |
13 |
Correct |
1 ms |
5724 KB |
Output is correct |
14 |
Correct |
1 ms |
5724 KB |
Output is correct |
15 |
Correct |
1 ms |
5724 KB |
Output is correct |
16 |
Correct |
1 ms |
5724 KB |
Output is correct |
17 |
Correct |
2 ms |
5720 KB |
Output is correct |
18 |
Correct |
2 ms |
5720 KB |
Output is correct |
19 |
Correct |
2 ms |
5724 KB |
Output is correct |
20 |
Correct |
1 ms |
5724 KB |
Output is correct |
21 |
Correct |
2 ms |
5724 KB |
Output is correct |
22 |
Correct |
2 ms |
5720 KB |
Output is correct |
23 |
Correct |
2 ms |
5724 KB |
Output is correct |
24 |
Correct |
2 ms |
5724 KB |
Output is correct |
25 |
Correct |
2 ms |
5764 KB |
Output is correct |
26 |
Correct |
2 ms |
5724 KB |
Output is correct |
27 |
Correct |
2 ms |
5724 KB |
Output is correct |
28 |
Correct |
2 ms |
5724 KB |
Output is correct |
29 |
Correct |
2 ms |
5852 KB |
Output is correct |
30 |
Correct |
2 ms |
5724 KB |
Output is correct |
31 |
Correct |
2 ms |
5724 KB |
Output is correct |
32 |
Correct |
2 ms |
5724 KB |
Output is correct |
33 |
Correct |
2 ms |
5720 KB |
Output is correct |
34 |
Correct |
2 ms |
5772 KB |
Output is correct |
35 |
Correct |
2 ms |
5724 KB |
Output is correct |
36 |
Correct |
2 ms |
5724 KB |
Output is correct |
37 |
Correct |
2 ms |
5848 KB |
Output is correct |
38 |
Correct |
2 ms |
5724 KB |
Output is correct |
39 |
Correct |
2 ms |
5724 KB |
Output is correct |
40 |
Correct |
2 ms |
5724 KB |
Output is correct |
41 |
Correct |
2 ms |
5724 KB |
Output is correct |
42 |
Correct |
2 ms |
5724 KB |
Output is correct |
43 |
Correct |
3 ms |
5980 KB |
Output is correct |
44 |
Correct |
2 ms |
5724 KB |
Output is correct |
45 |
Correct |
2 ms |
5724 KB |
Output is correct |
46 |
Correct |
2 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 |
5724 KB |
Output is correct |
50 |
Correct |
2 ms |
5780 KB |
Output is correct |
51 |
Correct |
2 ms |
5724 KB |
Output is correct |
52 |
Correct |
2 ms |
5720 KB |
Output is correct |
53 |
Correct |
2 ms |
5724 KB |
Output is correct |
54 |
Correct |
2 ms |
5724 KB |
Output is correct |
55 |
Correct |
2 ms |
5724 KB |
Output is correct |
56 |
Correct |
2 ms |
5724 KB |
Output is correct |
57 |
Correct |
3 ms |
5980 KB |
Output is correct |
58 |
Correct |
3 ms |
5724 KB |
Output is correct |
59 |
Correct |
2 ms |
5724 KB |
Output is correct |
60 |
Correct |
2 ms |
5724 KB |
Output is correct |
61 |
Correct |
2 ms |
5724 KB |
Output is correct |
62 |
Correct |
2 ms |
5724 KB |
Output is correct |
63 |
Correct |
2 ms |
5720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5724 KB |
Output is correct |
2 |
Correct |
2 ms |
5980 KB |
Output is correct |
3 |
Correct |
2 ms |
5720 KB |
Output is correct |
4 |
Correct |
1 ms |
5724 KB |
Output is correct |
5 |
Correct |
1 ms |
5760 KB |
Output is correct |
6 |
Correct |
1 ms |
5724 KB |
Output is correct |
7 |
Correct |
1 ms |
5724 KB |
Output is correct |
8 |
Correct |
1 ms |
5724 KB |
Output is correct |
9 |
Correct |
1 ms |
5724 KB |
Output is correct |
10 |
Correct |
1 ms |
5648 KB |
Output is correct |
11 |
Correct |
2 ms |
5724 KB |
Output is correct |
12 |
Correct |
1 ms |
5720 KB |
Output is correct |
13 |
Correct |
1 ms |
5724 KB |
Output is correct |
14 |
Correct |
1 ms |
5724 KB |
Output is correct |
15 |
Correct |
1 ms |
5724 KB |
Output is correct |
16 |
Correct |
1 ms |
5724 KB |
Output is correct |
17 |
Correct |
2 ms |
5720 KB |
Output is correct |
18 |
Correct |
2 ms |
5720 KB |
Output is correct |
19 |
Correct |
2 ms |
5724 KB |
Output is correct |
20 |
Correct |
1 ms |
5724 KB |
Output is correct |
21 |
Correct |
2 ms |
5724 KB |
Output is correct |
22 |
Correct |
2 ms |
5720 KB |
Output is correct |
23 |
Correct |
2 ms |
5724 KB |
Output is correct |
24 |
Correct |
2 ms |
5724 KB |
Output is correct |
25 |
Correct |
2 ms |
5764 KB |
Output is correct |
26 |
Correct |
2 ms |
5724 KB |
Output is correct |
27 |
Correct |
2 ms |
5724 KB |
Output is correct |
28 |
Correct |
2 ms |
5724 KB |
Output is correct |
29 |
Correct |
2 ms |
5852 KB |
Output is correct |
30 |
Correct |
2 ms |
5724 KB |
Output is correct |
31 |
Correct |
2 ms |
5724 KB |
Output is correct |
32 |
Correct |
2 ms |
5724 KB |
Output is correct |
33 |
Correct |
2 ms |
5720 KB |
Output is correct |
34 |
Correct |
2 ms |
5772 KB |
Output is correct |
35 |
Correct |
2 ms |
5724 KB |
Output is correct |
36 |
Correct |
2 ms |
5724 KB |
Output is correct |
37 |
Correct |
2 ms |
5848 KB |
Output is correct |
38 |
Correct |
2 ms |
5724 KB |
Output is correct |
39 |
Correct |
2 ms |
5724 KB |
Output is correct |
40 |
Correct |
2 ms |
5724 KB |
Output is correct |
41 |
Correct |
2 ms |
5724 KB |
Output is correct |
42 |
Correct |
2 ms |
5724 KB |
Output is correct |
43 |
Correct |
3 ms |
5980 KB |
Output is correct |
44 |
Correct |
2 ms |
5724 KB |
Output is correct |
45 |
Correct |
2 ms |
5724 KB |
Output is correct |
46 |
Correct |
2 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 |
5724 KB |
Output is correct |
50 |
Correct |
2 ms |
5780 KB |
Output is correct |
51 |
Correct |
2 ms |
5724 KB |
Output is correct |
52 |
Correct |
2 ms |
5720 KB |
Output is correct |
53 |
Correct |
2 ms |
5724 KB |
Output is correct |
54 |
Correct |
2 ms |
5724 KB |
Output is correct |
55 |
Correct |
2 ms |
5724 KB |
Output is correct |
56 |
Correct |
2 ms |
5724 KB |
Output is correct |
57 |
Correct |
3 ms |
5980 KB |
Output is correct |
58 |
Correct |
3 ms |
5724 KB |
Output is correct |
59 |
Correct |
2 ms |
5724 KB |
Output is correct |
60 |
Correct |
2 ms |
5724 KB |
Output is correct |
61 |
Correct |
2 ms |
5724 KB |
Output is correct |
62 |
Correct |
2 ms |
5724 KB |
Output is correct |
63 |
Correct |
2 ms |
5720 KB |
Output is correct |
64 |
Correct |
69 ms |
15140 KB |
Output is correct |
65 |
Correct |
92 ms |
15264 KB |
Output is correct |
66 |
Correct |
60 ms |
15228 KB |
Output is correct |
67 |
Correct |
62 ms |
15212 KB |
Output is correct |
68 |
Correct |
60 ms |
15136 KB |
Output is correct |
69 |
Correct |
78 ms |
15328 KB |
Output is correct |
70 |
Correct |
88 ms |
15308 KB |
Output is correct |
71 |
Correct |
97 ms |
15268 KB |
Output is correct |
72 |
Correct |
71 ms |
15152 KB |
Output is correct |
73 |
Correct |
99 ms |
27760 KB |
Output is correct |
74 |
Correct |
96 ms |
27676 KB |
Output is correct |
75 |
Correct |
71 ms |
15116 KB |
Output is correct |
76 |
Correct |
76 ms |
15164 KB |
Output is correct |
77 |
Correct |
63 ms |
15220 KB |
Output is correct |
78 |
Correct |
83 ms |
15160 KB |
Output is correct |
79 |
Correct |
62 ms |
15144 KB |
Output is correct |
80 |
Correct |
92 ms |
15208 KB |
Output is correct |
81 |
Correct |
59 ms |
15644 KB |
Output is correct |
82 |
Correct |
64 ms |
15344 KB |
Output is correct |
83 |
Correct |
89 ms |
20200 KB |
Output is correct |
84 |
Correct |
114 ms |
22356 KB |
Output is correct |
85 |
Correct |
94 ms |
22172 KB |
Output is correct |
86 |
Correct |
71 ms |
16528 KB |
Output is correct |
87 |
Correct |
82 ms |
16016 KB |
Output is correct |
88 |
Correct |
66 ms |
16396 KB |
Output is correct |
89 |
Correct |
62 ms |
16540 KB |
Output is correct |
90 |
Correct |
76 ms |
16308 KB |
Output is correct |
91 |
Correct |
81 ms |
16532 KB |
Output is correct |
92 |
Correct |
71 ms |
16732 KB |
Output is correct |
93 |
Correct |
77 ms |
19060 KB |
Output is correct |
94 |
Correct |
89 ms |
20868 KB |
Output is correct |
95 |
Correct |
67 ms |
19532 KB |
Output is correct |
96 |
Correct |
65 ms |
17844 KB |
Output is correct |
97 |
Correct |
75 ms |
16364 KB |
Output is correct |
98 |
Correct |
78 ms |
15812 KB |
Output is correct |
99 |
Correct |
71 ms |
15756 KB |
Output is correct |
100 |
Correct |
69 ms |
18848 KB |
Output is correct |
101 |
Correct |
71 ms |
16656 KB |
Output is correct |
102 |
Correct |
67 ms |
16060 KB |
Output is correct |
103 |
Correct |
81 ms |
15808 KB |
Output is correct |
104 |
Correct |
52 ms |
15816 KB |
Output is correct |
105 |
Correct |
120 ms |
24508 KB |
Output is correct |
106 |
Correct |
47 ms |
16072 KB |
Output is correct |
107 |
Correct |
59 ms |
15840 KB |
Output is correct |
108 |
Correct |
83 ms |
28304 KB |
Output is correct |
109 |
Correct |
61 ms |
16024 KB |
Output is correct |
110 |
Correct |
82 ms |
28724 KB |
Output is correct |
111 |
Correct |
57 ms |
15128 KB |
Output is correct |