Submission #908602

# Submission time Handle Problem Language Result Execution time Memory
908602 2024-01-16T15:03:21 Z arashMLG Power Plant (JOI20_power) C++17
100 / 100
281 ms 39760 KB
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=5e5+23;int n,dp[N][2],is[N];vector<int> G[N];void dfs(int v,int p=-1) {int sum0=0,sum1=0,mx1=0,mx0=0;for(int u:G[v]) if(u!=p) {dfs(u,v);sum0+=dp[u][0];sum1+=dp[u][1];mx1=max(mx1,dp[u][1]);mx0=max(mx0,dp[u][0]);}dp[v][0]=(is[v]?max({mx0,sum1-1,1+mx1}):max({mx0,sum1}));dp[v][1]=(is[v]?max({1,sum1-1}):sum1);}int main(){cin>>n;for(int i=1; i<n ; i++) {int v,u;cin>>v>>u;G[v].pb(u);G[u].pb(v);}for(int i=1;i<=n;i++) {char c; cin>>c;is[i]=(c=='1');}dfs(1);cout<<dp[1][0]<<'\n';}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14940 KB Output is correct
2 Correct 5 ms 14936 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 4 ms 14940 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 4 ms 14940 KB Output is correct
7 Correct 4 ms 14940 KB Output is correct
8 Correct 4 ms 14940 KB Output is correct
9 Correct 4 ms 14936 KB Output is correct
10 Correct 4 ms 14940 KB Output is correct
11 Correct 4 ms 14940 KB Output is correct
12 Correct 4 ms 14940 KB Output is correct
13 Correct 4 ms 14940 KB Output is correct
14 Correct 4 ms 14956 KB Output is correct
15 Correct 4 ms 14940 KB Output is correct
16 Correct 4 ms 14948 KB Output is correct
17 Correct 4 ms 14940 KB Output is correct
18 Correct 4 ms 14940 KB Output is correct
19 Correct 5 ms 14940 KB Output is correct
20 Correct 4 ms 14940 KB Output is correct
21 Correct 5 ms 14940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14940 KB Output is correct
2 Correct 5 ms 14936 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 4 ms 14940 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 4 ms 14940 KB Output is correct
7 Correct 4 ms 14940 KB Output is correct
8 Correct 4 ms 14940 KB Output is correct
9 Correct 4 ms 14936 KB Output is correct
10 Correct 4 ms 14940 KB Output is correct
11 Correct 4 ms 14940 KB Output is correct
12 Correct 4 ms 14940 KB Output is correct
13 Correct 4 ms 14940 KB Output is correct
14 Correct 4 ms 14956 KB Output is correct
15 Correct 4 ms 14940 KB Output is correct
16 Correct 4 ms 14948 KB Output is correct
17 Correct 4 ms 14940 KB Output is correct
18 Correct 4 ms 14940 KB Output is correct
19 Correct 5 ms 14940 KB Output is correct
20 Correct 4 ms 14940 KB Output is correct
21 Correct 5 ms 14940 KB Output is correct
22 Correct 7 ms 14936 KB Output is correct
23 Correct 7 ms 15112 KB Output is correct
24 Correct 6 ms 14936 KB Output is correct
25 Correct 5 ms 14936 KB Output is correct
26 Correct 5 ms 14936 KB Output is correct
27 Correct 5 ms 14940 KB Output is correct
28 Correct 5 ms 14956 KB Output is correct
29 Correct 5 ms 15196 KB Output is correct
30 Correct 5 ms 14940 KB Output is correct
31 Correct 5 ms 14940 KB Output is correct
32 Correct 5 ms 14940 KB Output is correct
33 Correct 5 ms 14952 KB Output is correct
34 Correct 5 ms 14972 KB Output is correct
35 Correct 5 ms 14940 KB Output is correct
36 Correct 5 ms 14936 KB Output is correct
37 Correct 5 ms 14936 KB Output is correct
38 Correct 5 ms 14940 KB Output is correct
39 Correct 5 ms 14964 KB Output is correct
40 Correct 6 ms 14940 KB Output is correct
41 Correct 6 ms 14952 KB Output is correct
42 Correct 5 ms 14940 KB Output is correct
43 Correct 5 ms 14940 KB Output is correct
44 Correct 5 ms 14940 KB Output is correct
45 Correct 5 ms 14940 KB Output is correct
46 Correct 5 ms 14936 KB Output is correct
47 Correct 5 ms 14940 KB Output is correct
48 Correct 5 ms 14940 KB Output is correct
49 Correct 5 ms 15148 KB Output is correct
50 Correct 5 ms 14940 KB Output is correct
51 Correct 5 ms 14940 KB Output is correct
52 Correct 6 ms 14940 KB Output is correct
53 Correct 5 ms 14940 KB Output is correct
54 Correct 5 ms 14940 KB Output is correct
55 Correct 5 ms 14940 KB Output is correct
56 Correct 4 ms 14940 KB Output is correct
57 Correct 5 ms 15048 KB Output is correct
58 Correct 5 ms 14940 KB Output is correct
59 Correct 5 ms 14940 KB Output is correct
60 Correct 5 ms 14940 KB Output is correct
61 Correct 5 ms 14940 KB Output is correct
62 Correct 5 ms 14984 KB Output is correct
63 Correct 5 ms 14936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14940 KB Output is correct
2 Correct 5 ms 14936 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 4 ms 14940 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 4 ms 14940 KB Output is correct
7 Correct 4 ms 14940 KB Output is correct
8 Correct 4 ms 14940 KB Output is correct
9 Correct 4 ms 14936 KB Output is correct
10 Correct 4 ms 14940 KB Output is correct
11 Correct 4 ms 14940 KB Output is correct
12 Correct 4 ms 14940 KB Output is correct
13 Correct 4 ms 14940 KB Output is correct
14 Correct 4 ms 14956 KB Output is correct
15 Correct 4 ms 14940 KB Output is correct
16 Correct 4 ms 14948 KB Output is correct
17 Correct 4 ms 14940 KB Output is correct
18 Correct 4 ms 14940 KB Output is correct
19 Correct 5 ms 14940 KB Output is correct
20 Correct 4 ms 14940 KB Output is correct
21 Correct 5 ms 14940 KB Output is correct
22 Correct 7 ms 14936 KB Output is correct
23 Correct 7 ms 15112 KB Output is correct
24 Correct 6 ms 14936 KB Output is correct
25 Correct 5 ms 14936 KB Output is correct
26 Correct 5 ms 14936 KB Output is correct
27 Correct 5 ms 14940 KB Output is correct
28 Correct 5 ms 14956 KB Output is correct
29 Correct 5 ms 15196 KB Output is correct
30 Correct 5 ms 14940 KB Output is correct
31 Correct 5 ms 14940 KB Output is correct
32 Correct 5 ms 14940 KB Output is correct
33 Correct 5 ms 14952 KB Output is correct
34 Correct 5 ms 14972 KB Output is correct
35 Correct 5 ms 14940 KB Output is correct
36 Correct 5 ms 14936 KB Output is correct
37 Correct 5 ms 14936 KB Output is correct
38 Correct 5 ms 14940 KB Output is correct
39 Correct 5 ms 14964 KB Output is correct
40 Correct 6 ms 14940 KB Output is correct
41 Correct 6 ms 14952 KB Output is correct
42 Correct 5 ms 14940 KB Output is correct
43 Correct 5 ms 14940 KB Output is correct
44 Correct 5 ms 14940 KB Output is correct
45 Correct 5 ms 14940 KB Output is correct
46 Correct 5 ms 14936 KB Output is correct
47 Correct 5 ms 14940 KB Output is correct
48 Correct 5 ms 14940 KB Output is correct
49 Correct 5 ms 15148 KB Output is correct
50 Correct 5 ms 14940 KB Output is correct
51 Correct 5 ms 14940 KB Output is correct
52 Correct 6 ms 14940 KB Output is correct
53 Correct 5 ms 14940 KB Output is correct
54 Correct 5 ms 14940 KB Output is correct
55 Correct 5 ms 14940 KB Output is correct
56 Correct 4 ms 14940 KB Output is correct
57 Correct 5 ms 15048 KB Output is correct
58 Correct 5 ms 14940 KB Output is correct
59 Correct 5 ms 14940 KB Output is correct
60 Correct 5 ms 14940 KB Output is correct
61 Correct 5 ms 14940 KB Output is correct
62 Correct 5 ms 14984 KB Output is correct
63 Correct 5 ms 14936 KB Output is correct
64 Correct 203 ms 23392 KB Output is correct
65 Correct 144 ms 23380 KB Output is correct
66 Correct 179 ms 23268 KB Output is correct
67 Correct 145 ms 23376 KB Output is correct
68 Correct 151 ms 23376 KB Output is correct
69 Correct 204 ms 23172 KB Output is correct
70 Correct 162 ms 23380 KB Output is correct
71 Correct 149 ms 23628 KB Output is correct
72 Correct 169 ms 23380 KB Output is correct
73 Correct 211 ms 38560 KB Output is correct
74 Correct 206 ms 38484 KB Output is correct
75 Correct 183 ms 23116 KB Output is correct
76 Correct 183 ms 23568 KB Output is correct
77 Correct 150 ms 23192 KB Output is correct
78 Correct 165 ms 23288 KB Output is correct
79 Correct 178 ms 23056 KB Output is correct
80 Correct 184 ms 23124 KB Output is correct
81 Correct 146 ms 23748 KB Output is correct
82 Correct 171 ms 23488 KB Output is correct
83 Correct 230 ms 29328 KB Output is correct
84 Correct 203 ms 32080 KB Output is correct
85 Correct 195 ms 31572 KB Output is correct
86 Correct 192 ms 24912 KB Output is correct
87 Correct 163 ms 24216 KB Output is correct
88 Correct 159 ms 24740 KB Output is correct
89 Correct 148 ms 24616 KB Output is correct
90 Correct 178 ms 24400 KB Output is correct
91 Correct 161 ms 24656 KB Output is correct
92 Correct 186 ms 25172 KB Output is correct
93 Correct 185 ms 28000 KB Output is correct
94 Correct 174 ms 30136 KB Output is correct
95 Correct 171 ms 28504 KB Output is correct
96 Correct 174 ms 26416 KB Output is correct
97 Correct 197 ms 24464 KB Output is correct
98 Correct 149 ms 23936 KB Output is correct
99 Correct 149 ms 23632 KB Output is correct
100 Correct 222 ms 27384 KB Output is correct
101 Correct 173 ms 25020 KB Output is correct
102 Correct 187 ms 24380 KB Output is correct
103 Correct 200 ms 23812 KB Output is correct
104 Correct 152 ms 23872 KB Output is correct
105 Correct 207 ms 34620 KB Output is correct
106 Correct 155 ms 24004 KB Output is correct
107 Correct 123 ms 23992 KB Output is correct
108 Correct 179 ms 39456 KB Output is correct
109 Correct 159 ms 24060 KB Output is correct
110 Correct 281 ms 39760 KB Output is correct
111 Correct 223 ms 23272 KB Output is correct