# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
317226 | 2020-10-29T06:37:46 Z | tasfiq4 | Power Plant (JOI20_power) | C++14 | 221 ms | 29112 KB |
#include <bits/stdc++.h> using namespace std; typedef pair<int,int > pii; typedef long long int lld; #define pi acos(-1) #define fr(i,m,n) for(i=m;i<n;i++) #define fu(i,m,n) for(i=m;i>=n;i--) #define vec vector<int> #define pb push_back #define pp pop_back() #define ft first #define sd second #define all(v) v.begin(),v.end() #define mom(ara) memset(ara,0,sizeof(ara)); #define m1m(ara) memset(ara,-1,sizeof(ara)); #define endl "\n" #define eps 1.19209e-07 vec adj[200010]; int val[200010],dp[200010],ans=0; void dfs(int u ,int p) { int sum=0,mx=0; for(auto v:adj[u]) { if(v==p) continue; dfs(v,u); sum+=dp[v]; mx=max(mx,dp[v]); } if(val[u]) ans=max(ans,max(mx+1,sum-1)); else ans=max(ans,sum); dp[u]=max(val[u],sum-val[u]); } int main() {ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0); int i,j,k,a,b,c,x,y,z,n,m,t; cin>>n; string s; fr(i,1,n){ cin>>a>>b; adj[a].pb(b); adj[b].pb(a); } getline(cin,s); cin>>s; fr(i,0,s.size()) { if(s[i]=='1') val[i+1]=1; } dfs(1,0); cout<<ans<<endl; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 4992 KB | Output is correct |
2 | Correct | 4 ms | 4992 KB | Output is correct |
3 | Correct | 4 ms | 4992 KB | Output is correct |
4 | Correct | 4 ms | 4992 KB | Output is correct |
5 | Correct | 4 ms | 4992 KB | Output is correct |
6 | Correct | 4 ms | 4992 KB | Output is correct |
7 | Correct | 4 ms | 4992 KB | Output is correct |
8 | Correct | 4 ms | 4992 KB | Output is correct |
9 | Correct | 4 ms | 4992 KB | Output is correct |
10 | Correct | 4 ms | 4992 KB | Output is correct |
11 | Correct | 4 ms | 4992 KB | Output is correct |
12 | Correct | 3 ms | 4992 KB | Output is correct |
13 | Correct | 4 ms | 4992 KB | Output is correct |
14 | Correct | 4 ms | 4992 KB | Output is correct |
15 | Correct | 4 ms | 4992 KB | Output is correct |
16 | Correct | 3 ms | 4992 KB | Output is correct |
17 | Correct | 4 ms | 5120 KB | Output is correct |
18 | Correct | 4 ms | 4992 KB | Output is correct |
19 | Correct | 4 ms | 4992 KB | Output is correct |
20 | Correct | 4 ms | 4992 KB | Output is correct |
21 | Correct | 4 ms | 4992 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 4992 KB | Output is correct |
2 | Correct | 4 ms | 4992 KB | Output is correct |
3 | Correct | 4 ms | 4992 KB | Output is correct |
4 | Correct | 4 ms | 4992 KB | Output is correct |
5 | Correct | 4 ms | 4992 KB | Output is correct |
6 | Correct | 4 ms | 4992 KB | Output is correct |
7 | Correct | 4 ms | 4992 KB | Output is correct |
8 | Correct | 4 ms | 4992 KB | Output is correct |
9 | Correct | 4 ms | 4992 KB | Output is correct |
10 | Correct | 4 ms | 4992 KB | Output is correct |
11 | Correct | 4 ms | 4992 KB | Output is correct |
12 | Correct | 3 ms | 4992 KB | Output is correct |
13 | Correct | 4 ms | 4992 KB | Output is correct |
14 | Correct | 4 ms | 4992 KB | Output is correct |
15 | Correct | 4 ms | 4992 KB | Output is correct |
16 | Correct | 3 ms | 4992 KB | Output is correct |
17 | Correct | 4 ms | 5120 KB | Output is correct |
18 | Correct | 4 ms | 4992 KB | Output is correct |
19 | Correct | 4 ms | 4992 KB | Output is correct |
20 | Correct | 4 ms | 4992 KB | Output is correct |
21 | Correct | 4 ms | 4992 KB | Output is correct |
22 | Correct | 5 ms | 5120 KB | Output is correct |
23 | Correct | 5 ms | 5120 KB | Output is correct |
24 | Correct | 4 ms | 5120 KB | Output is correct |
25 | Correct | 5 ms | 5120 KB | Output is correct |
26 | Correct | 4 ms | 5120 KB | Output is correct |
27 | Correct | 5 ms | 5120 KB | Output is correct |
28 | Correct | 4 ms | 5120 KB | Output is correct |
29 | Correct | 5 ms | 5248 KB | Output is correct |
30 | Correct | 5 ms | 5248 KB | Output is correct |
31 | Correct | 5 ms | 5120 KB | Output is correct |
32 | Correct | 4 ms | 5120 KB | Output is correct |
33 | Correct | 5 ms | 5120 KB | Output is correct |
34 | Correct | 6 ms | 5248 KB | Output is correct |
35 | Correct | 4 ms | 5120 KB | Output is correct |
36 | Correct | 4 ms | 5120 KB | Output is correct |
37 | Correct | 5 ms | 5248 KB | Output is correct |
38 | Correct | 4 ms | 5120 KB | Output is correct |
39 | Correct | 5 ms | 5248 KB | Output is correct |
40 | Correct | 4 ms | 5120 KB | Output is correct |
41 | Correct | 4 ms | 5248 KB | Output is correct |
42 | Correct | 5 ms | 5120 KB | Output is correct |
43 | Correct | 4 ms | 5120 KB | Output is correct |
44 | Correct | 4 ms | 5120 KB | Output is correct |
45 | Correct | 5 ms | 5120 KB | Output is correct |
46 | Correct | 4 ms | 5120 KB | Output is correct |
47 | Correct | 4 ms | 5120 KB | Output is correct |
48 | Correct | 4 ms | 5248 KB | Output is correct |
49 | Correct | 5 ms | 5248 KB | Output is correct |
50 | Correct | 4 ms | 5120 KB | Output is correct |
51 | Correct | 4 ms | 5120 KB | Output is correct |
52 | Correct | 4 ms | 5120 KB | Output is correct |
53 | Correct | 4 ms | 5120 KB | Output is correct |
54 | Correct | 4 ms | 5120 KB | Output is correct |
55 | Correct | 4 ms | 5120 KB | Output is correct |
56 | Correct | 4 ms | 5120 KB | Output is correct |
57 | Correct | 4 ms | 5248 KB | Output is correct |
58 | Correct | 4 ms | 5120 KB | Output is correct |
59 | Correct | 4 ms | 5120 KB | Output is correct |
60 | Correct | 4 ms | 5248 KB | Output is correct |
61 | Correct | 5 ms | 5120 KB | Output is correct |
62 | Correct | 5 ms | 5280 KB | Output is correct |
63 | Correct | 5 ms | 5120 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 4992 KB | Output is correct |
2 | Correct | 4 ms | 4992 KB | Output is correct |
3 | Correct | 4 ms | 4992 KB | Output is correct |
4 | Correct | 4 ms | 4992 KB | Output is correct |
5 | Correct | 4 ms | 4992 KB | Output is correct |
6 | Correct | 4 ms | 4992 KB | Output is correct |
7 | Correct | 4 ms | 4992 KB | Output is correct |
8 | Correct | 4 ms | 4992 KB | Output is correct |
9 | Correct | 4 ms | 4992 KB | Output is correct |
10 | Correct | 4 ms | 4992 KB | Output is correct |
11 | Correct | 4 ms | 4992 KB | Output is correct |
12 | Correct | 3 ms | 4992 KB | Output is correct |
13 | Correct | 4 ms | 4992 KB | Output is correct |
14 | Correct | 4 ms | 4992 KB | Output is correct |
15 | Correct | 4 ms | 4992 KB | Output is correct |
16 | Correct | 3 ms | 4992 KB | Output is correct |
17 | Correct | 4 ms | 5120 KB | Output is correct |
18 | Correct | 4 ms | 4992 KB | Output is correct |
19 | Correct | 4 ms | 4992 KB | Output is correct |
20 | Correct | 4 ms | 4992 KB | Output is correct |
21 | Correct | 4 ms | 4992 KB | Output is correct |
22 | Correct | 5 ms | 5120 KB | Output is correct |
23 | Correct | 5 ms | 5120 KB | Output is correct |
24 | Correct | 4 ms | 5120 KB | Output is correct |
25 | Correct | 5 ms | 5120 KB | Output is correct |
26 | Correct | 4 ms | 5120 KB | Output is correct |
27 | Correct | 5 ms | 5120 KB | Output is correct |
28 | Correct | 4 ms | 5120 KB | Output is correct |
29 | Correct | 5 ms | 5248 KB | Output is correct |
30 | Correct | 5 ms | 5248 KB | Output is correct |
31 | Correct | 5 ms | 5120 KB | Output is correct |
32 | Correct | 4 ms | 5120 KB | Output is correct |
33 | Correct | 5 ms | 5120 KB | Output is correct |
34 | Correct | 6 ms | 5248 KB | Output is correct |
35 | Correct | 4 ms | 5120 KB | Output is correct |
36 | Correct | 4 ms | 5120 KB | Output is correct |
37 | Correct | 5 ms | 5248 KB | Output is correct |
38 | Correct | 4 ms | 5120 KB | Output is correct |
39 | Correct | 5 ms | 5248 KB | Output is correct |
40 | Correct | 4 ms | 5120 KB | Output is correct |
41 | Correct | 4 ms | 5248 KB | Output is correct |
42 | Correct | 5 ms | 5120 KB | Output is correct |
43 | Correct | 4 ms | 5120 KB | Output is correct |
44 | Correct | 4 ms | 5120 KB | Output is correct |
45 | Correct | 5 ms | 5120 KB | Output is correct |
46 | Correct | 4 ms | 5120 KB | Output is correct |
47 | Correct | 4 ms | 5120 KB | Output is correct |
48 | Correct | 4 ms | 5248 KB | Output is correct |
49 | Correct | 5 ms | 5248 KB | Output is correct |
50 | Correct | 4 ms | 5120 KB | Output is correct |
51 | Correct | 4 ms | 5120 KB | Output is correct |
52 | Correct | 4 ms | 5120 KB | Output is correct |
53 | Correct | 4 ms | 5120 KB | Output is correct |
54 | Correct | 4 ms | 5120 KB | Output is correct |
55 | Correct | 4 ms | 5120 KB | Output is correct |
56 | Correct | 4 ms | 5120 KB | Output is correct |
57 | Correct | 4 ms | 5248 KB | Output is correct |
58 | Correct | 4 ms | 5120 KB | Output is correct |
59 | Correct | 4 ms | 5120 KB | Output is correct |
60 | Correct | 4 ms | 5248 KB | Output is correct |
61 | Correct | 5 ms | 5120 KB | Output is correct |
62 | Correct | 5 ms | 5280 KB | Output is correct |
63 | Correct | 5 ms | 5120 KB | Output is correct |
64 | Correct | 176 ms | 16188 KB | Output is correct |
65 | Correct | 173 ms | 16056 KB | Output is correct |
66 | Correct | 176 ms | 16036 KB | Output is correct |
67 | Correct | 173 ms | 16056 KB | Output is correct |
68 | Correct | 173 ms | 16036 KB | Output is correct |
69 | Correct | 173 ms | 16180 KB | Output is correct |
70 | Correct | 173 ms | 15940 KB | Output is correct |
71 | Correct | 169 ms | 15940 KB | Output is correct |
72 | Correct | 174 ms | 15244 KB | Output is correct |
73 | Correct | 208 ms | 28596 KB | Output is correct |
74 | Correct | 193 ms | 28728 KB | Output is correct |
75 | Correct | 172 ms | 15928 KB | Output is correct |
76 | Correct | 180 ms | 15952 KB | Output is correct |
77 | Correct | 180 ms | 15924 KB | Output is correct |
78 | Correct | 219 ms | 15928 KB | Output is correct |
79 | Correct | 177 ms | 15936 KB | Output is correct |
80 | Correct | 181 ms | 15880 KB | Output is correct |
81 | Correct | 146 ms | 16372 KB | Output is correct |
82 | Correct | 170 ms | 16120 KB | Output is correct |
83 | Correct | 192 ms | 21052 KB | Output is correct |
84 | Correct | 186 ms | 23240 KB | Output is correct |
85 | Correct | 186 ms | 22980 KB | Output is correct |
86 | Correct | 177 ms | 17336 KB | Output is correct |
87 | Correct | 171 ms | 16820 KB | Output is correct |
88 | Correct | 162 ms | 17268 KB | Output is correct |
89 | Correct | 162 ms | 17224 KB | Output is correct |
90 | Correct | 169 ms | 17052 KB | Output is correct |
91 | Correct | 162 ms | 17208 KB | Output is correct |
92 | Correct | 169 ms | 17600 KB | Output is correct |
93 | Correct | 153 ms | 19972 KB | Output is correct |
94 | Correct | 151 ms | 21744 KB | Output is correct |
95 | Correct | 149 ms | 20464 KB | Output is correct |
96 | Correct | 159 ms | 18724 KB | Output is correct |
97 | Correct | 162 ms | 17172 KB | Output is correct |
98 | Correct | 151 ms | 16616 KB | Output is correct |
99 | Correct | 173 ms | 16436 KB | Output is correct |
100 | Correct | 155 ms | 19492 KB | Output is correct |
101 | Correct | 160 ms | 17460 KB | Output is correct |
102 | Correct | 157 ms | 16712 KB | Output is correct |
103 | Correct | 163 ms | 16600 KB | Output is correct |
104 | Correct | 96 ms | 16108 KB | Output is correct |
105 | Correct | 221 ms | 24632 KB | Output is correct |
106 | Correct | 99 ms | 16780 KB | Output is correct |
107 | Correct | 99 ms | 16744 KB | Output is correct |
108 | Correct | 197 ms | 28600 KB | Output is correct |
109 | Correct | 103 ms | 16104 KB | Output is correct |
110 | Correct | 197 ms | 29112 KB | Output is correct |
111 | Correct | 161 ms | 15908 KB | Output is correct |