Submission #568058

# Submission time Handle Problem Language Result Execution time Memory
568058 2022-05-24T14:54:07 Z fadi57 Power Plant (JOI20_power) C++14
100 / 100
297 ms 32364 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(mark[node]){
      ans=max(ans,maxi+1);
        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);
    }
  }*/
  dfs(0,-1);
  cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 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 3 ms 4948 KB Output is correct
9 Correct 4 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 4 ms 4948 KB Output is correct
15 Correct 4 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 4 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 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 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 3 ms 4948 KB Output is correct
9 Correct 4 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 4 ms 4948 KB Output is correct
15 Correct 4 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 4 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 4 ms 5076 KB Output is correct
24 Correct 4 ms 5076 KB Output is correct
25 Correct 4 ms 5076 KB Output is correct
26 Correct 4 ms 5076 KB Output is correct
27 Correct 4 ms 5076 KB Output is correct
28 Correct 4 ms 5076 KB Output is correct
29 Correct 4 ms 5204 KB Output is correct
30 Correct 4 ms 5204 KB Output is correct
31 Correct 5 ms 5076 KB Output is correct
32 Correct 4 ms 5076 KB Output is correct
33 Correct 4 ms 5076 KB Output is correct
34 Correct 4 ms 5076 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 4 ms 5076 KB Output is correct
37 Correct 4 ms 5076 KB Output is correct
38 Correct 4 ms 5076 KB Output is correct
39 Correct 4 ms 5076 KB Output is correct
40 Correct 4 ms 5076 KB Output is correct
41 Correct 4 ms 5076 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 4 ms 5076 KB Output is correct
46 Correct 5 ms 5076 KB Output is correct
47 Correct 4 ms 5076 KB Output is correct
48 Correct 4 ms 5076 KB Output is correct
49 Correct 6 ms 5188 KB Output is correct
50 Correct 5 ms 5076 KB Output is correct
51 Correct 4 ms 5076 KB Output is correct
52 Correct 4 ms 5076 KB Output is correct
53 Correct 4 ms 5072 KB Output is correct
54 Correct 4 ms 5076 KB Output is correct
55 Correct 4 ms 5076 KB Output is correct
56 Correct 3 ms 5076 KB Output is correct
57 Correct 4 ms 5204 KB Output is correct
58 Correct 3 ms 5076 KB Output is correct
59 Correct 4 ms 5076 KB Output is correct
60 Correct 4 ms 5076 KB Output is correct
61 Correct 4 ms 5076 KB Output is correct
62 Correct 4 ms 5204 KB Output is correct
63 Correct 4 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 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 3 ms 4948 KB Output is correct
9 Correct 4 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 4 ms 4948 KB Output is correct
15 Correct 4 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 4 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 4 ms 5076 KB Output is correct
24 Correct 4 ms 5076 KB Output is correct
25 Correct 4 ms 5076 KB Output is correct
26 Correct 4 ms 5076 KB Output is correct
27 Correct 4 ms 5076 KB Output is correct
28 Correct 4 ms 5076 KB Output is correct
29 Correct 4 ms 5204 KB Output is correct
30 Correct 4 ms 5204 KB Output is correct
31 Correct 5 ms 5076 KB Output is correct
32 Correct 4 ms 5076 KB Output is correct
33 Correct 4 ms 5076 KB Output is correct
34 Correct 4 ms 5076 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 4 ms 5076 KB Output is correct
37 Correct 4 ms 5076 KB Output is correct
38 Correct 4 ms 5076 KB Output is correct
39 Correct 4 ms 5076 KB Output is correct
40 Correct 4 ms 5076 KB Output is correct
41 Correct 4 ms 5076 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 4 ms 5076 KB Output is correct
46 Correct 5 ms 5076 KB Output is correct
47 Correct 4 ms 5076 KB Output is correct
48 Correct 4 ms 5076 KB Output is correct
49 Correct 6 ms 5188 KB Output is correct
50 Correct 5 ms 5076 KB Output is correct
51 Correct 4 ms 5076 KB Output is correct
52 Correct 4 ms 5076 KB Output is correct
53 Correct 4 ms 5072 KB Output is correct
54 Correct 4 ms 5076 KB Output is correct
55 Correct 4 ms 5076 KB Output is correct
56 Correct 3 ms 5076 KB Output is correct
57 Correct 4 ms 5204 KB Output is correct
58 Correct 3 ms 5076 KB Output is correct
59 Correct 4 ms 5076 KB Output is correct
60 Correct 4 ms 5076 KB Output is correct
61 Correct 4 ms 5076 KB Output is correct
62 Correct 4 ms 5204 KB Output is correct
63 Correct 4 ms 4984 KB Output is correct
64 Correct 268 ms 13204 KB Output is correct
65 Correct 196 ms 15976 KB Output is correct
66 Correct 200 ms 15868 KB Output is correct
67 Correct 225 ms 15964 KB Output is correct
68 Correct 203 ms 15896 KB Output is correct
69 Correct 203 ms 15884 KB Output is correct
70 Correct 254 ms 15860 KB Output is correct
71 Correct 195 ms 16056 KB Output is correct
72 Correct 209 ms 15984 KB Output is correct
73 Correct 297 ms 31124 KB Output is correct
74 Correct 213 ms 31180 KB Output is correct
75 Correct 239 ms 15836 KB Output is correct
76 Correct 200 ms 15792 KB Output is correct
77 Correct 200 ms 15752 KB Output is correct
78 Correct 220 ms 15808 KB Output is correct
79 Correct 228 ms 15756 KB Output is correct
80 Correct 199 ms 15744 KB Output is correct
81 Correct 179 ms 16304 KB Output is correct
82 Correct 207 ms 16212 KB Output is correct
83 Correct 239 ms 22060 KB Output is correct
84 Correct 216 ms 24572 KB Output is correct
85 Correct 252 ms 24440 KB Output is correct
86 Correct 235 ms 17568 KB Output is correct
87 Correct 213 ms 16924 KB Output is correct
88 Correct 228 ms 17304 KB Output is correct
89 Correct 190 ms 17248 KB Output is correct
90 Correct 215 ms 17072 KB Output is correct
91 Correct 219 ms 17444 KB Output is correct
92 Correct 195 ms 17656 KB Output is correct
93 Correct 229 ms 20540 KB Output is correct
94 Correct 212 ms 22756 KB Output is correct
95 Correct 206 ms 21228 KB Output is correct
96 Correct 207 ms 19032 KB Output is correct
97 Correct 206 ms 17064 KB Output is correct
98 Correct 216 ms 16512 KB Output is correct
99 Correct 196 ms 16280 KB Output is correct
100 Correct 268 ms 20120 KB Output is correct
101 Correct 208 ms 17776 KB Output is correct
102 Correct 211 ms 16716 KB Output is correct
103 Correct 244 ms 16540 KB Output is correct
104 Correct 167 ms 16840 KB Output is correct
105 Correct 231 ms 27236 KB Output is correct
106 Correct 146 ms 16592 KB Output is correct
107 Correct 168 ms 16680 KB Output is correct
108 Correct 265 ms 31912 KB Output is correct
109 Correct 152 ms 16828 KB Output is correct
110 Correct 219 ms 32364 KB Output is correct
111 Correct 242 ms 15836 KB Output is correct