# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
306041 | 2020-09-24T10:57:47 Z | TadijaSebez | Power Plant (JOI20_power) | C++11 | 1116 ms | 27896 KB |
#include <bits/stdc++.h> using namespace std; #define pb push_back const int N=200050; vector<int> E[N]; char s[N]; int sz[N],was[N]; void DFS(int u,int p){sz[u]=1;for(int v:E[u])if(!was[v]&&v!=p)DFS(v,u),sz[u]+=sz[v];} int Find(int u,int p,int n){for(int v:E[u])if(!was[v]&&v!=p&&sz[v]*2>=n)return Find(v,u,n);return u;} int Find(int u){DFS(u,u);u=Find(u,u,sz[u]);was[u]=1;return u;} int ans,dp[N]; void DP(int u,int p){ int sum=0; dp[u]=s[u]=='1'?1:0; for(int v:E[u])if(!was[v]&&v!=p){ DP(v,u); sum+=dp[v]; } if(s[u]=='1')dp[u]=max(dp[u],sum-1); else dp[u]=max(dp[u],sum); } void Decompose(int u){ u=Find(u); int sum=0; for(int v:E[u])if(!was[v]){ DP(v,u); if(s[u]=='1')ans=max(ans,dp[v]+1); sum+=dp[v]; } if(s[u]=='1')ans=max(ans,sum-1),ans=max(ans,1); else ans=max(ans,sum); for(int v:E[u])if(!was[v])Decompose(v); } int main(){ int n; scanf("%i",&n); for(int i=1,u,v;i<n;i++)scanf("%i %i",&u,&v),E[u].pb(v),E[v].pb(u); scanf("%s",s+1); Decompose(1); printf("%i\n",ans); return 0; }
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 | 5 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 | 4 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 | 4 ms | 4992 KB | Output is correct |
17 | Correct | 4 ms | 4992 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 | 5 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 | 4 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 | 4 ms | 4992 KB | Output is correct |
17 | Correct | 4 ms | 4992 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 | 6 ms | 5120 KB | Output is correct |
23 | Correct | 5 ms | 5120 KB | Output is correct |
24 | Correct | 6 ms | 5120 KB | Output is correct |
25 | Correct | 5 ms | 5120 KB | Output is correct |
26 | Correct | 5 ms | 5120 KB | Output is correct |
27 | Correct | 5 ms | 5120 KB | Output is correct |
28 | Correct | 5 ms | 5120 KB | Output is correct |
29 | Correct | 6 ms | 5248 KB | Output is correct |
30 | Correct | 6 ms | 5248 KB | Output is correct |
31 | Correct | 5 ms | 5120 KB | Output is correct |
32 | Correct | 5 ms | 5120 KB | Output is correct |
33 | Correct | 5 ms | 5120 KB | Output is correct |
34 | Correct | 5 ms | 5120 KB | Output is correct |
35 | Correct | 6 ms | 5120 KB | Output is correct |
36 | Correct | 5 ms | 5120 KB | Output is correct |
37 | Correct | 5 ms | 5120 KB | Output is correct |
38 | Correct | 5 ms | 5120 KB | Output is correct |
39 | Correct | 6 ms | 5248 KB | Output is correct |
40 | Correct | 6 ms | 5120 KB | Output is correct |
41 | Correct | 6 ms | 5248 KB | Output is correct |
42 | Correct | 6 ms | 5120 KB | Output is correct |
43 | Correct | 6 ms | 5120 KB | Output is correct |
44 | Correct | 5 ms | 5120 KB | Output is correct |
45 | Correct | 5 ms | 5120 KB | Output is correct |
46 | Correct | 5 ms | 5120 KB | Output is correct |
47 | Correct | 5 ms | 5120 KB | Output is correct |
48 | Correct | 5 ms | 5248 KB | Output is correct |
49 | Correct | 6 ms | 5248 KB | Output is correct |
50 | Correct | 6 ms | 5120 KB | Output is correct |
51 | Correct | 6 ms | 5224 KB | Output is correct |
52 | Correct | 5 ms | 5120 KB | Output is correct |
53 | Correct | 5 ms | 5120 KB | Output is correct |
54 | Correct | 5 ms | 5120 KB | Output is correct |
55 | Correct | 5 ms | 5120 KB | Output is correct |
56 | Correct | 5 ms | 5120 KB | Output is correct |
57 | Correct | 6 ms | 5248 KB | Output is correct |
58 | Correct | 5 ms | 5120 KB | Output is correct |
59 | Correct | 5 ms | 5120 KB | Output is correct |
60 | Correct | 6 ms | 5248 KB | Output is correct |
61 | Correct | 5 ms | 5120 KB | Output is correct |
62 | Correct | 6 ms | 5248 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 | 5 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 | 4 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 | 4 ms | 4992 KB | Output is correct |
17 | Correct | 4 ms | 4992 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 | 6 ms | 5120 KB | Output is correct |
23 | Correct | 5 ms | 5120 KB | Output is correct |
24 | Correct | 6 ms | 5120 KB | Output is correct |
25 | Correct | 5 ms | 5120 KB | Output is correct |
26 | Correct | 5 ms | 5120 KB | Output is correct |
27 | Correct | 5 ms | 5120 KB | Output is correct |
28 | Correct | 5 ms | 5120 KB | Output is correct |
29 | Correct | 6 ms | 5248 KB | Output is correct |
30 | Correct | 6 ms | 5248 KB | Output is correct |
31 | Correct | 5 ms | 5120 KB | Output is correct |
32 | Correct | 5 ms | 5120 KB | Output is correct |
33 | Correct | 5 ms | 5120 KB | Output is correct |
34 | Correct | 5 ms | 5120 KB | Output is correct |
35 | Correct | 6 ms | 5120 KB | Output is correct |
36 | Correct | 5 ms | 5120 KB | Output is correct |
37 | Correct | 5 ms | 5120 KB | Output is correct |
38 | Correct | 5 ms | 5120 KB | Output is correct |
39 | Correct | 6 ms | 5248 KB | Output is correct |
40 | Correct | 6 ms | 5120 KB | Output is correct |
41 | Correct | 6 ms | 5248 KB | Output is correct |
42 | Correct | 6 ms | 5120 KB | Output is correct |
43 | Correct | 6 ms | 5120 KB | Output is correct |
44 | Correct | 5 ms | 5120 KB | Output is correct |
45 | Correct | 5 ms | 5120 KB | Output is correct |
46 | Correct | 5 ms | 5120 KB | Output is correct |
47 | Correct | 5 ms | 5120 KB | Output is correct |
48 | Correct | 5 ms | 5248 KB | Output is correct |
49 | Correct | 6 ms | 5248 KB | Output is correct |
50 | Correct | 6 ms | 5120 KB | Output is correct |
51 | Correct | 6 ms | 5224 KB | Output is correct |
52 | Correct | 5 ms | 5120 KB | Output is correct |
53 | Correct | 5 ms | 5120 KB | Output is correct |
54 | Correct | 5 ms | 5120 KB | Output is correct |
55 | Correct | 5 ms | 5120 KB | Output is correct |
56 | Correct | 5 ms | 5120 KB | Output is correct |
57 | Correct | 6 ms | 5248 KB | Output is correct |
58 | Correct | 5 ms | 5120 KB | Output is correct |
59 | Correct | 5 ms | 5120 KB | Output is correct |
60 | Correct | 6 ms | 5248 KB | Output is correct |
61 | Correct | 5 ms | 5120 KB | Output is correct |
62 | Correct | 6 ms | 5248 KB | Output is correct |
63 | Correct | 5 ms | 5120 KB | Output is correct |
64 | Correct | 651 ms | 16764 KB | Output is correct |
65 | Correct | 611 ms | 16828 KB | Output is correct |
66 | Correct | 624 ms | 16760 KB | Output is correct |
67 | Correct | 678 ms | 16888 KB | Output is correct |
68 | Correct | 615 ms | 16752 KB | Output is correct |
69 | Correct | 626 ms | 16888 KB | Output is correct |
70 | Correct | 610 ms | 16608 KB | Output is correct |
71 | Correct | 624 ms | 16888 KB | Output is correct |
72 | Correct | 647 ms | 16888 KB | Output is correct |
73 | Correct | 1116 ms | 26772 KB | Output is correct |
74 | Correct | 1088 ms | 26836 KB | Output is correct |
75 | Correct | 636 ms | 16628 KB | Output is correct |
76 | Correct | 628 ms | 16632 KB | Output is correct |
77 | Correct | 711 ms | 16572 KB | Output is correct |
78 | Correct | 720 ms | 16504 KB | Output is correct |
79 | Correct | 723 ms | 16676 KB | Output is correct |
80 | Correct | 705 ms | 16504 KB | Output is correct |
81 | Correct | 240 ms | 16880 KB | Output is correct |
82 | Correct | 273 ms | 16864 KB | Output is correct |
83 | Correct | 885 ms | 20728 KB | Output is correct |
84 | Correct | 923 ms | 22392 KB | Output is correct |
85 | Correct | 893 ms | 22136 KB | Output is correct |
86 | Correct | 730 ms | 17656 KB | Output is correct |
87 | Correct | 718 ms | 17400 KB | Output is correct |
88 | Correct | 519 ms | 17660 KB | Output is correct |
89 | Correct | 532 ms | 17784 KB | Output is correct |
90 | Correct | 532 ms | 17656 KB | Output is correct |
91 | Correct | 557 ms | 17984 KB | Output is correct |
92 | Correct | 515 ms | 18040 KB | Output is correct |
93 | Correct | 605 ms | 22256 KB | Output is correct |
94 | Correct | 583 ms | 23536 KB | Output is correct |
95 | Correct | 565 ms | 20340 KB | Output is correct |
96 | Correct | 573 ms | 19208 KB | Output is correct |
97 | Correct | 479 ms | 17656 KB | Output is correct |
98 | Correct | 449 ms | 17144 KB | Output is correct |
99 | Correct | 490 ms | 17144 KB | Output is correct |
100 | Correct | 593 ms | 19576 KB | Output is correct |
101 | Correct | 543 ms | 17912 KB | Output is correct |
102 | Correct | 508 ms | 17528 KB | Output is correct |
103 | Correct | 559 ms | 17144 KB | Output is correct |
104 | Correct | 143 ms | 17384 KB | Output is correct |
105 | Correct | 1095 ms | 24440 KB | Output is correct |
106 | Correct | 150 ms | 17256 KB | Output is correct |
107 | Correct | 144 ms | 17260 KB | Output is correct |
108 | Correct | 1054 ms | 27384 KB | Output is correct |
109 | Correct | 148 ms | 17512 KB | Output is correct |
110 | Correct | 1075 ms | 27896 KB | Output is correct |
111 | Correct | 454 ms | 16632 KB | Output is correct |