# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
568057 |
2022-05-24T14:50:30 Z |
fadi57 |
Power Plant (JOI20_power) |
C++14 |
|
1500 ms |
15988 KB |
#include<bits/stdc++.h>
using namespace std;
const int mx=2e5+5;
vector<int>adj[mx];
int mark[mx];
int ans;
int dp[mx];
void dfs(int node,int par){
int sum=0;
int maxi=0;
for(auto it:adj[node]){
if(it!=par){
dfs(it,node);
sum+=dp[it];
maxi=max(maxi,dp[it]);
}
}
if(node==par){
ans=max(maxi+1,ans);
}
if(mark[node]){
dp[node]=max(sum-1,1);
}else{
dp[node]=sum;
}
ans=max(ans,dp[node]);
}
int main(){
int n;cin>>n;
for(int i=0;i<n-1;i++){
int x,y;
cin>>x>>y;
x--;y--;
adj[x].push_back(y); adj[y].push_back(x);
}
string x;cin>>x;
for(int i=0;i<n;i++){
mark[i]=(x[i]=='1');
}
for(int i=0;i<n;i++){
if(mark[i]){
dfs(i,i);
}
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
5004 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
5000 KB |
Output is correct |
15 |
Correct |
3 ms |
5000 KB |
Output is correct |
16 |
Correct |
3 ms |
5004 KB |
Output is correct |
17 |
Correct |
3 ms |
5004 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
4 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
5004 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
5000 KB |
Output is correct |
15 |
Correct |
3 ms |
5000 KB |
Output is correct |
16 |
Correct |
3 ms |
5004 KB |
Output is correct |
17 |
Correct |
3 ms |
5004 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
4 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
75 ms |
5016 KB |
Output is correct |
23 |
Correct |
68 ms |
5096 KB |
Output is correct |
24 |
Correct |
63 ms |
5196 KB |
Output is correct |
25 |
Correct |
40 ms |
5092 KB |
Output is correct |
26 |
Correct |
23 ms |
5076 KB |
Output is correct |
27 |
Correct |
11 ms |
5076 KB |
Output is correct |
28 |
Correct |
4 ms |
5076 KB |
Output is correct |
29 |
Correct |
92 ms |
5276 KB |
Output is correct |
30 |
Correct |
53 ms |
5280 KB |
Output is correct |
31 |
Correct |
68 ms |
5088 KB |
Output is correct |
32 |
Correct |
38 ms |
5076 KB |
Output is correct |
33 |
Correct |
65 ms |
5076 KB |
Output is correct |
34 |
Correct |
41 ms |
5088 KB |
Output is correct |
35 |
Correct |
23 ms |
5076 KB |
Output is correct |
36 |
Correct |
11 ms |
5076 KB |
Output is correct |
37 |
Correct |
51 ms |
5012 KB |
Output is correct |
38 |
Correct |
42 ms |
5076 KB |
Output is correct |
39 |
Correct |
82 ms |
5196 KB |
Output is correct |
40 |
Correct |
48 ms |
5200 KB |
Output is correct |
41 |
Correct |
26 ms |
5184 KB |
Output is correct |
42 |
Correct |
45 ms |
5072 KB |
Output is correct |
43 |
Correct |
14 ms |
5156 KB |
Output is correct |
44 |
Correct |
66 ms |
5136 KB |
Output is correct |
45 |
Correct |
56 ms |
5204 KB |
Output is correct |
46 |
Correct |
35 ms |
5076 KB |
Output is correct |
47 |
Correct |
21 ms |
5076 KB |
Output is correct |
48 |
Correct |
59 ms |
5204 KB |
Output is correct |
49 |
Correct |
58 ms |
5076 KB |
Output is correct |
50 |
Correct |
59 ms |
5160 KB |
Output is correct |
51 |
Correct |
78 ms |
5140 KB |
Output is correct |
52 |
Correct |
60 ms |
5076 KB |
Output is correct |
53 |
Correct |
50 ms |
5076 KB |
Output is correct |
54 |
Correct |
58 ms |
5140 KB |
Output is correct |
55 |
Correct |
60 ms |
5112 KB |
Output is correct |
56 |
Correct |
4 ms |
5016 KB |
Output is correct |
57 |
Correct |
4 ms |
5204 KB |
Output is correct |
58 |
Correct |
34 ms |
5012 KB |
Output is correct |
59 |
Correct |
33 ms |
5104 KB |
Output is correct |
60 |
Correct |
4 ms |
5204 KB |
Output is correct |
61 |
Correct |
4 ms |
5076 KB |
Output is correct |
62 |
Correct |
6 ms |
5276 KB |
Output is correct |
63 |
Correct |
57 ms |
5100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
5004 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
5000 KB |
Output is correct |
15 |
Correct |
3 ms |
5000 KB |
Output is correct |
16 |
Correct |
3 ms |
5004 KB |
Output is correct |
17 |
Correct |
3 ms |
5004 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
4 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
75 ms |
5016 KB |
Output is correct |
23 |
Correct |
68 ms |
5096 KB |
Output is correct |
24 |
Correct |
63 ms |
5196 KB |
Output is correct |
25 |
Correct |
40 ms |
5092 KB |
Output is correct |
26 |
Correct |
23 ms |
5076 KB |
Output is correct |
27 |
Correct |
11 ms |
5076 KB |
Output is correct |
28 |
Correct |
4 ms |
5076 KB |
Output is correct |
29 |
Correct |
92 ms |
5276 KB |
Output is correct |
30 |
Correct |
53 ms |
5280 KB |
Output is correct |
31 |
Correct |
68 ms |
5088 KB |
Output is correct |
32 |
Correct |
38 ms |
5076 KB |
Output is correct |
33 |
Correct |
65 ms |
5076 KB |
Output is correct |
34 |
Correct |
41 ms |
5088 KB |
Output is correct |
35 |
Correct |
23 ms |
5076 KB |
Output is correct |
36 |
Correct |
11 ms |
5076 KB |
Output is correct |
37 |
Correct |
51 ms |
5012 KB |
Output is correct |
38 |
Correct |
42 ms |
5076 KB |
Output is correct |
39 |
Correct |
82 ms |
5196 KB |
Output is correct |
40 |
Correct |
48 ms |
5200 KB |
Output is correct |
41 |
Correct |
26 ms |
5184 KB |
Output is correct |
42 |
Correct |
45 ms |
5072 KB |
Output is correct |
43 |
Correct |
14 ms |
5156 KB |
Output is correct |
44 |
Correct |
66 ms |
5136 KB |
Output is correct |
45 |
Correct |
56 ms |
5204 KB |
Output is correct |
46 |
Correct |
35 ms |
5076 KB |
Output is correct |
47 |
Correct |
21 ms |
5076 KB |
Output is correct |
48 |
Correct |
59 ms |
5204 KB |
Output is correct |
49 |
Correct |
58 ms |
5076 KB |
Output is correct |
50 |
Correct |
59 ms |
5160 KB |
Output is correct |
51 |
Correct |
78 ms |
5140 KB |
Output is correct |
52 |
Correct |
60 ms |
5076 KB |
Output is correct |
53 |
Correct |
50 ms |
5076 KB |
Output is correct |
54 |
Correct |
58 ms |
5140 KB |
Output is correct |
55 |
Correct |
60 ms |
5112 KB |
Output is correct |
56 |
Correct |
4 ms |
5016 KB |
Output is correct |
57 |
Correct |
4 ms |
5204 KB |
Output is correct |
58 |
Correct |
34 ms |
5012 KB |
Output is correct |
59 |
Correct |
33 ms |
5104 KB |
Output is correct |
60 |
Correct |
4 ms |
5204 KB |
Output is correct |
61 |
Correct |
4 ms |
5076 KB |
Output is correct |
62 |
Correct |
6 ms |
5276 KB |
Output is correct |
63 |
Correct |
57 ms |
5100 KB |
Output is correct |
64 |
Execution timed out |
1578 ms |
15988 KB |
Time limit exceeded |
65 |
Halted |
0 ms |
0 KB |
- |