# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
696472 |
2023-02-06T15:10:21 Z |
dsyz |
Power Plant (JOI20_power) |
C++17 |
|
171 ms |
29876 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAXN (200005)
vector<ll> v[MAXN];
bool generator[MAXN];
ll dp[MAXN];
ll ans = 0;
void dfs(ll x,ll p){
ll maximum = 0;
ll sum = 0;
for(auto u : v[x]){
if(u != p){
dfs(u,x);
maximum = max(maximum,dp[u]);
sum += dp[u];
}
}
if(generator[x]){
dp[x] = max(1ll,sum - generator[x]);
}else{
dp[x] = sum - generator[x];
}
ans = max(ans,dp[x]);
ans = max(ans,maximum + generator[x]);
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);
ll N;
cin>>N;
for(ll i = 0;i < N - 1;i++){
ll a,b;
cin>>a>>b;
a--;
b--;
v[a].push_back(b);
v[b].push_back(a);
}
string s;
cin>>s;
for(ll i = 0;i < N;i++){
if(s[i] == '0') generator[i] = 0;
else generator[i] = 1;
}
dfs(0,-1);
cout<<ans<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5036 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
5036 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
5040 KB |
Output is correct |
11 |
Correct |
3 ms |
5040 KB |
Output is correct |
12 |
Correct |
3 ms |
5036 KB |
Output is correct |
13 |
Correct |
4 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
5032 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
2 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5036 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
5036 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
5040 KB |
Output is correct |
11 |
Correct |
3 ms |
5040 KB |
Output is correct |
12 |
Correct |
3 ms |
5036 KB |
Output is correct |
13 |
Correct |
4 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
5032 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
2 ms |
4948 KB |
Output is correct |
22 |
Correct |
4 ms |
5076 KB |
Output is correct |
23 |
Correct |
3 ms |
5076 KB |
Output is correct |
24 |
Correct |
3 ms |
5076 KB |
Output is correct |
25 |
Correct |
3 ms |
5076 KB |
Output is correct |
26 |
Correct |
3 ms |
5076 KB |
Output is correct |
27 |
Correct |
3 ms |
5076 KB |
Output is correct |
28 |
Correct |
3 ms |
5044 KB |
Output is correct |
29 |
Correct |
3 ms |
5176 KB |
Output is correct |
30 |
Correct |
3 ms |
5176 KB |
Output is correct |
31 |
Correct |
3 ms |
5116 KB |
Output is correct |
32 |
Correct |
3 ms |
5048 KB |
Output is correct |
33 |
Correct |
4 ms |
5048 KB |
Output is correct |
34 |
Correct |
3 ms |
5076 KB |
Output is correct |
35 |
Correct |
3 ms |
5076 KB |
Output is correct |
36 |
Correct |
3 ms |
5048 KB |
Output is correct |
37 |
Correct |
4 ms |
5204 KB |
Output is correct |
38 |
Correct |
3 ms |
5048 KB |
Output is correct |
39 |
Correct |
3 ms |
5180 KB |
Output is correct |
40 |
Correct |
4 ms |
5076 KB |
Output is correct |
41 |
Correct |
4 ms |
5204 KB |
Output is correct |
42 |
Correct |
4 ms |
5076 KB |
Output is correct |
43 |
Correct |
4 ms |
5076 KB |
Output is correct |
44 |
Correct |
4 ms |
5076 KB |
Output is correct |
45 |
Correct |
3 ms |
5076 KB |
Output is correct |
46 |
Correct |
3 ms |
5076 KB |
Output is correct |
47 |
Correct |
4 ms |
5076 KB |
Output is correct |
48 |
Correct |
4 ms |
5204 KB |
Output is correct |
49 |
Correct |
4 ms |
5204 KB |
Output is correct |
50 |
Correct |
3 ms |
5176 KB |
Output is correct |
51 |
Correct |
3 ms |
5176 KB |
Output is correct |
52 |
Correct |
3 ms |
5048 KB |
Output is correct |
53 |
Correct |
3 ms |
5096 KB |
Output is correct |
54 |
Correct |
5 ms |
5076 KB |
Output is correct |
55 |
Correct |
3 ms |
5100 KB |
Output is correct |
56 |
Correct |
4 ms |
5044 KB |
Output is correct |
57 |
Correct |
3 ms |
5172 KB |
Output is correct |
58 |
Correct |
4 ms |
5076 KB |
Output is correct |
59 |
Correct |
3 ms |
5052 KB |
Output is correct |
60 |
Correct |
3 ms |
5172 KB |
Output is correct |
61 |
Correct |
3 ms |
5076 KB |
Output is correct |
62 |
Correct |
3 ms |
5172 KB |
Output is correct |
63 |
Correct |
3 ms |
5076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5036 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
5036 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
5040 KB |
Output is correct |
11 |
Correct |
3 ms |
5040 KB |
Output is correct |
12 |
Correct |
3 ms |
5036 KB |
Output is correct |
13 |
Correct |
4 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
5032 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
2 ms |
4948 KB |
Output is correct |
22 |
Correct |
4 ms |
5076 KB |
Output is correct |
23 |
Correct |
3 ms |
5076 KB |
Output is correct |
24 |
Correct |
3 ms |
5076 KB |
Output is correct |
25 |
Correct |
3 ms |
5076 KB |
Output is correct |
26 |
Correct |
3 ms |
5076 KB |
Output is correct |
27 |
Correct |
3 ms |
5076 KB |
Output is correct |
28 |
Correct |
3 ms |
5044 KB |
Output is correct |
29 |
Correct |
3 ms |
5176 KB |
Output is correct |
30 |
Correct |
3 ms |
5176 KB |
Output is correct |
31 |
Correct |
3 ms |
5116 KB |
Output is correct |
32 |
Correct |
3 ms |
5048 KB |
Output is correct |
33 |
Correct |
4 ms |
5048 KB |
Output is correct |
34 |
Correct |
3 ms |
5076 KB |
Output is correct |
35 |
Correct |
3 ms |
5076 KB |
Output is correct |
36 |
Correct |
3 ms |
5048 KB |
Output is correct |
37 |
Correct |
4 ms |
5204 KB |
Output is correct |
38 |
Correct |
3 ms |
5048 KB |
Output is correct |
39 |
Correct |
3 ms |
5180 KB |
Output is correct |
40 |
Correct |
4 ms |
5076 KB |
Output is correct |
41 |
Correct |
4 ms |
5204 KB |
Output is correct |
42 |
Correct |
4 ms |
5076 KB |
Output is correct |
43 |
Correct |
4 ms |
5076 KB |
Output is correct |
44 |
Correct |
4 ms |
5076 KB |
Output is correct |
45 |
Correct |
3 ms |
5076 KB |
Output is correct |
46 |
Correct |
3 ms |
5076 KB |
Output is correct |
47 |
Correct |
4 ms |
5076 KB |
Output is correct |
48 |
Correct |
4 ms |
5204 KB |
Output is correct |
49 |
Correct |
4 ms |
5204 KB |
Output is correct |
50 |
Correct |
3 ms |
5176 KB |
Output is correct |
51 |
Correct |
3 ms |
5176 KB |
Output is correct |
52 |
Correct |
3 ms |
5048 KB |
Output is correct |
53 |
Correct |
3 ms |
5096 KB |
Output is correct |
54 |
Correct |
5 ms |
5076 KB |
Output is correct |
55 |
Correct |
3 ms |
5100 KB |
Output is correct |
56 |
Correct |
4 ms |
5044 KB |
Output is correct |
57 |
Correct |
3 ms |
5172 KB |
Output is correct |
58 |
Correct |
4 ms |
5076 KB |
Output is correct |
59 |
Correct |
3 ms |
5052 KB |
Output is correct |
60 |
Correct |
3 ms |
5172 KB |
Output is correct |
61 |
Correct |
3 ms |
5076 KB |
Output is correct |
62 |
Correct |
3 ms |
5172 KB |
Output is correct |
63 |
Correct |
3 ms |
5076 KB |
Output is correct |
64 |
Correct |
115 ms |
17168 KB |
Output is correct |
65 |
Correct |
134 ms |
17140 KB |
Output is correct |
66 |
Correct |
148 ms |
17148 KB |
Output is correct |
67 |
Correct |
117 ms |
17044 KB |
Output is correct |
68 |
Correct |
129 ms |
17064 KB |
Output is correct |
69 |
Correct |
115 ms |
17160 KB |
Output is correct |
70 |
Correct |
125 ms |
17092 KB |
Output is correct |
71 |
Correct |
111 ms |
17140 KB |
Output is correct |
72 |
Correct |
116 ms |
17132 KB |
Output is correct |
73 |
Correct |
162 ms |
28688 KB |
Output is correct |
74 |
Correct |
137 ms |
28748 KB |
Output is correct |
75 |
Correct |
120 ms |
18340 KB |
Output is correct |
76 |
Correct |
130 ms |
18336 KB |
Output is correct |
77 |
Correct |
135 ms |
17216 KB |
Output is correct |
78 |
Correct |
135 ms |
17040 KB |
Output is correct |
79 |
Correct |
130 ms |
17080 KB |
Output is correct |
80 |
Correct |
159 ms |
17032 KB |
Output is correct |
81 |
Correct |
93 ms |
17092 KB |
Output is correct |
82 |
Correct |
114 ms |
17152 KB |
Output is correct |
83 |
Correct |
171 ms |
22156 KB |
Output is correct |
84 |
Correct |
132 ms |
24428 KB |
Output is correct |
85 |
Correct |
121 ms |
23960 KB |
Output is correct |
86 |
Correct |
132 ms |
18444 KB |
Output is correct |
87 |
Correct |
125 ms |
17924 KB |
Output is correct |
88 |
Correct |
116 ms |
17936 KB |
Output is correct |
89 |
Correct |
120 ms |
18060 KB |
Output is correct |
90 |
Correct |
122 ms |
17820 KB |
Output is correct |
91 |
Correct |
120 ms |
18036 KB |
Output is correct |
92 |
Correct |
105 ms |
18372 KB |
Output is correct |
93 |
Correct |
110 ms |
20656 KB |
Output is correct |
94 |
Correct |
107 ms |
22204 KB |
Output is correct |
95 |
Correct |
110 ms |
20976 KB |
Output is correct |
96 |
Correct |
111 ms |
19184 KB |
Output is correct |
97 |
Correct |
120 ms |
17708 KB |
Output is correct |
98 |
Correct |
117 ms |
17248 KB |
Output is correct |
99 |
Correct |
126 ms |
17248 KB |
Output is correct |
100 |
Correct |
108 ms |
20184 KB |
Output is correct |
101 |
Correct |
105 ms |
17988 KB |
Output is correct |
102 |
Correct |
104 ms |
17396 KB |
Output is correct |
103 |
Correct |
122 ms |
17396 KB |
Output is correct |
104 |
Correct |
69 ms |
17824 KB |
Output is correct |
105 |
Correct |
143 ms |
25568 KB |
Output is correct |
106 |
Correct |
76 ms |
17724 KB |
Output is correct |
107 |
Correct |
85 ms |
17684 KB |
Output is correct |
108 |
Correct |
141 ms |
29520 KB |
Output is correct |
109 |
Correct |
74 ms |
17744 KB |
Output is correct |
110 |
Correct |
127 ms |
29876 KB |
Output is correct |
111 |
Correct |
102 ms |
17036 KB |
Output is correct |