# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
951807 |
2024-03-22T16:54:14 Z |
dio_2 |
Power Plant (JOI20_power) |
C++17 |
|
91 ms |
28708 KB |
#include<bits/stdc++.h>
using namespace std;
const int nax = (int)2e5 + 10;
bool isGen[nax];
vector<int> g[nax];
int ans;
int dp[nax];
void dfs(int u, int par){
if(isGen[u]){
int best = 0;
for(int v : g[u]) if(v != par){
dfs(v, u);
dp[u] += dp[v];
best = max(best, dp[v] + 1); // use the Generator on v.
}
ans = max(ans, best);
dp[u]--; // because i have generator and it will break
dp[u] = max(dp[u], 1); // it will break only if i have > 2.
} else {
for(int v : g[u]) if(v != par){
dfs(v, u);
dp[u] += dp[v];
}
}
ans = max(ans, dp[u]);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
for(int i = 1;i < n;i++){
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
for(int i = 1;i <= n;i++){
char c; cin >> c;
if(c == '1') isGen[i] = 1;
}
dfs(1, -1);
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5720 KB |
Output is correct |
2 |
Correct |
2 ms |
5724 KB |
Output is correct |
3 |
Correct |
2 ms |
5724 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 |
5724 KB |
Output is correct |
7 |
Correct |
2 ms |
5724 KB |
Output is correct |
8 |
Correct |
2 ms |
5720 KB |
Output is correct |
9 |
Correct |
1 ms |
5724 KB |
Output is correct |
10 |
Correct |
2 ms |
5720 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 |
5724 KB |
Output is correct |
18 |
Correct |
2 ms |
5724 KB |
Output is correct |
19 |
Correct |
1 ms |
5724 KB |
Output is correct |
20 |
Correct |
2 ms |
5756 KB |
Output is correct |
21 |
Correct |
2 ms |
5724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5720 KB |
Output is correct |
2 |
Correct |
2 ms |
5724 KB |
Output is correct |
3 |
Correct |
2 ms |
5724 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 |
5724 KB |
Output is correct |
7 |
Correct |
2 ms |
5724 KB |
Output is correct |
8 |
Correct |
2 ms |
5720 KB |
Output is correct |
9 |
Correct |
1 ms |
5724 KB |
Output is correct |
10 |
Correct |
2 ms |
5720 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 |
5724 KB |
Output is correct |
18 |
Correct |
2 ms |
5724 KB |
Output is correct |
19 |
Correct |
1 ms |
5724 KB |
Output is correct |
20 |
Correct |
2 ms |
5756 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 |
5720 KB |
Output is correct |
24 |
Correct |
2 ms |
5720 KB |
Output is correct |
25 |
Correct |
2 ms |
5724 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 |
3 ms |
5724 KB |
Output is correct |
30 |
Correct |
2 ms |
5812 KB |
Output is correct |
31 |
Correct |
2 ms |
5720 KB |
Output is correct |
32 |
Correct |
2 ms |
5724 KB |
Output is correct |
33 |
Correct |
2 ms |
5724 KB |
Output is correct |
34 |
Correct |
2 ms |
5720 KB |
Output is correct |
35 |
Correct |
2 ms |
5724 KB |
Output is correct |
36 |
Correct |
2 ms |
5840 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 |
5720 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 |
5880 KB |
Output is correct |
43 |
Correct |
2 ms |
5724 KB |
Output is correct |
44 |
Correct |
2 ms |
5720 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 |
5724 KB |
Output is correct |
51 |
Correct |
2 ms |
5724 KB |
Output is correct |
52 |
Correct |
2 ms |
5724 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 |
2 ms |
5980 KB |
Output is correct |
58 |
Correct |
2 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 |
5768 KB |
Output is correct |
63 |
Correct |
2 ms |
5724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5720 KB |
Output is correct |
2 |
Correct |
2 ms |
5724 KB |
Output is correct |
3 |
Correct |
2 ms |
5724 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 |
5724 KB |
Output is correct |
7 |
Correct |
2 ms |
5724 KB |
Output is correct |
8 |
Correct |
2 ms |
5720 KB |
Output is correct |
9 |
Correct |
1 ms |
5724 KB |
Output is correct |
10 |
Correct |
2 ms |
5720 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 |
5724 KB |
Output is correct |
18 |
Correct |
2 ms |
5724 KB |
Output is correct |
19 |
Correct |
1 ms |
5724 KB |
Output is correct |
20 |
Correct |
2 ms |
5756 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 |
5720 KB |
Output is correct |
24 |
Correct |
2 ms |
5720 KB |
Output is correct |
25 |
Correct |
2 ms |
5724 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 |
3 ms |
5724 KB |
Output is correct |
30 |
Correct |
2 ms |
5812 KB |
Output is correct |
31 |
Correct |
2 ms |
5720 KB |
Output is correct |
32 |
Correct |
2 ms |
5724 KB |
Output is correct |
33 |
Correct |
2 ms |
5724 KB |
Output is correct |
34 |
Correct |
2 ms |
5720 KB |
Output is correct |
35 |
Correct |
2 ms |
5724 KB |
Output is correct |
36 |
Correct |
2 ms |
5840 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 |
5720 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 |
5880 KB |
Output is correct |
43 |
Correct |
2 ms |
5724 KB |
Output is correct |
44 |
Correct |
2 ms |
5720 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 |
5724 KB |
Output is correct |
51 |
Correct |
2 ms |
5724 KB |
Output is correct |
52 |
Correct |
2 ms |
5724 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 |
2 ms |
5980 KB |
Output is correct |
58 |
Correct |
2 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 |
5768 KB |
Output is correct |
63 |
Correct |
2 ms |
5724 KB |
Output is correct |
64 |
Correct |
84 ms |
15444 KB |
Output is correct |
65 |
Correct |
67 ms |
15188 KB |
Output is correct |
66 |
Correct |
65 ms |
15188 KB |
Output is correct |
67 |
Correct |
62 ms |
15092 KB |
Output is correct |
68 |
Correct |
65 ms |
15184 KB |
Output is correct |
69 |
Correct |
65 ms |
14980 KB |
Output is correct |
70 |
Correct |
59 ms |
15204 KB |
Output is correct |
71 |
Correct |
70 ms |
15096 KB |
Output is correct |
72 |
Correct |
60 ms |
14928 KB |
Output is correct |
73 |
Correct |
91 ms |
27724 KB |
Output is correct |
74 |
Correct |
82 ms |
27732 KB |
Output is correct |
75 |
Correct |
57 ms |
15024 KB |
Output is correct |
76 |
Correct |
67 ms |
14932 KB |
Output is correct |
77 |
Correct |
63 ms |
14904 KB |
Output is correct |
78 |
Correct |
63 ms |
15092 KB |
Output is correct |
79 |
Correct |
58 ms |
14888 KB |
Output is correct |
80 |
Correct |
59 ms |
14940 KB |
Output is correct |
81 |
Correct |
58 ms |
15320 KB |
Output is correct |
82 |
Correct |
61 ms |
15312 KB |
Output is correct |
83 |
Correct |
71 ms |
20304 KB |
Output is correct |
84 |
Correct |
88 ms |
22500 KB |
Output is correct |
85 |
Correct |
86 ms |
21996 KB |
Output is correct |
86 |
Correct |
64 ms |
16468 KB |
Output is correct |
87 |
Correct |
62 ms |
15952 KB |
Output is correct |
88 |
Correct |
60 ms |
16212 KB |
Output is correct |
89 |
Correct |
77 ms |
16288 KB |
Output is correct |
90 |
Correct |
67 ms |
16208 KB |
Output is correct |
91 |
Correct |
68 ms |
16384 KB |
Output is correct |
92 |
Correct |
62 ms |
16720 KB |
Output is correct |
93 |
Correct |
60 ms |
18932 KB |
Output is correct |
94 |
Correct |
61 ms |
20676 KB |
Output is correct |
95 |
Correct |
63 ms |
19524 KB |
Output is correct |
96 |
Correct |
58 ms |
17672 KB |
Output is correct |
97 |
Correct |
54 ms |
16208 KB |
Output is correct |
98 |
Correct |
56 ms |
15700 KB |
Output is correct |
99 |
Correct |
73 ms |
15952 KB |
Output is correct |
100 |
Correct |
60 ms |
18512 KB |
Output is correct |
101 |
Correct |
71 ms |
16692 KB |
Output is correct |
102 |
Correct |
55 ms |
15884 KB |
Output is correct |
103 |
Correct |
56 ms |
15696 KB |
Output is correct |
104 |
Correct |
43 ms |
15568 KB |
Output is correct |
105 |
Correct |
75 ms |
24404 KB |
Output is correct |
106 |
Correct |
41 ms |
15560 KB |
Output is correct |
107 |
Correct |
42 ms |
15556 KB |
Output is correct |
108 |
Correct |
79 ms |
28240 KB |
Output is correct |
109 |
Correct |
48 ms |
15608 KB |
Output is correct |
110 |
Correct |
79 ms |
28708 KB |
Output is correct |
111 |
Correct |
54 ms |
14928 KB |
Output is correct |