Submission #402352

# Submission time Handle Problem Language Result Execution time Memory
402352 2021-05-11T15:52:12 Z wildturtle Power Plant (JOI20_power) C++14
100 / 100
321 ms 32788 KB
#include<bits/stdc++.h>
#define ll long long
#define f first
#define sc second
#define pb push_back
using namespace std;
ll a,b,c,d,i,e,f,g,n,m,k,l,ans,A[500005],B[500005];
vector <ll> v[500005];
string s;
void dfs(ll x,ll y) {
    for(ll i=0;i<v[x].size();i++) {
        if(v[x][i]==y) continue;
        dfs(v[x][i],x);
        A[x]+=A[v[x][i]];
        B[x]+=B[v[x][i]];
    }
    if(s[x-1]=='1') { A[x]=max(A[x]-1, (ll)1 ); B[x]++; }
    
}
int main() {
    cin>>n;
    for(ll i=1;i<n;i++) {
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    cin>>s;
    a=0;
    for(ll i=0;i<n;i++) {
        if(s[i]=='1') a++;
    }
    dfs(1,0);
    for(ll x=1;x<=n;x++) {
        //cout<<x<<" "<<A[x]<<" "<<B[x]<<" "<<a<<endl;
        if(B[x]<a) ans=max(ans,A[x]+1);
        else ans=max(ans,A[x]);
    }
    cout<<ans;
}

Compilation message

power.cpp: In function 'void dfs(long long int, long long int)':
power.cpp:11:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for(ll i=0;i<v[x].size();i++) {
      |                ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 11980 KB Output is correct
2 Correct 7 ms 11980 KB Output is correct
3 Correct 9 ms 12032 KB Output is correct
4 Correct 9 ms 12028 KB Output is correct
5 Correct 8 ms 11992 KB Output is correct
6 Correct 8 ms 11980 KB Output is correct
7 Correct 7 ms 11980 KB Output is correct
8 Correct 9 ms 11980 KB Output is correct
9 Correct 8 ms 12008 KB Output is correct
10 Correct 8 ms 11980 KB Output is correct
11 Correct 9 ms 11980 KB Output is correct
12 Correct 8 ms 11980 KB Output is correct
13 Correct 9 ms 12044 KB Output is correct
14 Correct 9 ms 12040 KB Output is correct
15 Correct 8 ms 11980 KB Output is correct
16 Correct 8 ms 11980 KB Output is correct
17 Correct 8 ms 11980 KB Output is correct
18 Correct 8 ms 12000 KB Output is correct
19 Correct 7 ms 12052 KB Output is correct
20 Correct 8 ms 11980 KB Output is correct
21 Correct 8 ms 12016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 11980 KB Output is correct
2 Correct 7 ms 11980 KB Output is correct
3 Correct 9 ms 12032 KB Output is correct
4 Correct 9 ms 12028 KB Output is correct
5 Correct 8 ms 11992 KB Output is correct
6 Correct 8 ms 11980 KB Output is correct
7 Correct 7 ms 11980 KB Output is correct
8 Correct 9 ms 11980 KB Output is correct
9 Correct 8 ms 12008 KB Output is correct
10 Correct 8 ms 11980 KB Output is correct
11 Correct 9 ms 11980 KB Output is correct
12 Correct 8 ms 11980 KB Output is correct
13 Correct 9 ms 12044 KB Output is correct
14 Correct 9 ms 12040 KB Output is correct
15 Correct 8 ms 11980 KB Output is correct
16 Correct 8 ms 11980 KB Output is correct
17 Correct 8 ms 11980 KB Output is correct
18 Correct 8 ms 12000 KB Output is correct
19 Correct 7 ms 12052 KB Output is correct
20 Correct 8 ms 11980 KB Output is correct
21 Correct 8 ms 12016 KB Output is correct
22 Correct 9 ms 12180 KB Output is correct
23 Correct 10 ms 12048 KB Output is correct
24 Correct 11 ms 12108 KB Output is correct
25 Correct 10 ms 12108 KB Output is correct
26 Correct 10 ms 12108 KB Output is correct
27 Correct 11 ms 12184 KB Output is correct
28 Correct 10 ms 12156 KB Output is correct
29 Correct 10 ms 12208 KB Output is correct
30 Correct 10 ms 12184 KB Output is correct
31 Correct 10 ms 12184 KB Output is correct
32 Correct 11 ms 12128 KB Output is correct
33 Correct 11 ms 12180 KB Output is correct
34 Correct 12 ms 12072 KB Output is correct
35 Correct 9 ms 12108 KB Output is correct
36 Correct 9 ms 12160 KB Output is correct
37 Correct 9 ms 12184 KB Output is correct
38 Correct 9 ms 12108 KB Output is correct
39 Correct 9 ms 12108 KB Output is correct
40 Correct 10 ms 12180 KB Output is correct
41 Correct 9 ms 12180 KB Output is correct
42 Correct 11 ms 12180 KB Output is correct
43 Correct 8 ms 12108 KB Output is correct
44 Correct 10 ms 12108 KB Output is correct
45 Correct 11 ms 12108 KB Output is correct
46 Correct 10 ms 12236 KB Output is correct
47 Correct 12 ms 12108 KB Output is correct
48 Correct 11 ms 12184 KB Output is correct
49 Correct 11 ms 12124 KB Output is correct
50 Correct 10 ms 12108 KB Output is correct
51 Correct 10 ms 12180 KB Output is correct
52 Correct 10 ms 12108 KB Output is correct
53 Correct 10 ms 12180 KB Output is correct
54 Correct 10 ms 12108 KB Output is correct
55 Correct 10 ms 12108 KB Output is correct
56 Correct 10 ms 12108 KB Output is correct
57 Correct 10 ms 12244 KB Output is correct
58 Correct 11 ms 12196 KB Output is correct
59 Correct 10 ms 12068 KB Output is correct
60 Correct 11 ms 12180 KB Output is correct
61 Correct 11 ms 12108 KB Output is correct
62 Correct 10 ms 12236 KB Output is correct
63 Correct 10 ms 12108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 11980 KB Output is correct
2 Correct 7 ms 11980 KB Output is correct
3 Correct 9 ms 12032 KB Output is correct
4 Correct 9 ms 12028 KB Output is correct
5 Correct 8 ms 11992 KB Output is correct
6 Correct 8 ms 11980 KB Output is correct
7 Correct 7 ms 11980 KB Output is correct
8 Correct 9 ms 11980 KB Output is correct
9 Correct 8 ms 12008 KB Output is correct
10 Correct 8 ms 11980 KB Output is correct
11 Correct 9 ms 11980 KB Output is correct
12 Correct 8 ms 11980 KB Output is correct
13 Correct 9 ms 12044 KB Output is correct
14 Correct 9 ms 12040 KB Output is correct
15 Correct 8 ms 11980 KB Output is correct
16 Correct 8 ms 11980 KB Output is correct
17 Correct 8 ms 11980 KB Output is correct
18 Correct 8 ms 12000 KB Output is correct
19 Correct 7 ms 12052 KB Output is correct
20 Correct 8 ms 11980 KB Output is correct
21 Correct 8 ms 12016 KB Output is correct
22 Correct 9 ms 12180 KB Output is correct
23 Correct 10 ms 12048 KB Output is correct
24 Correct 11 ms 12108 KB Output is correct
25 Correct 10 ms 12108 KB Output is correct
26 Correct 10 ms 12108 KB Output is correct
27 Correct 11 ms 12184 KB Output is correct
28 Correct 10 ms 12156 KB Output is correct
29 Correct 10 ms 12208 KB Output is correct
30 Correct 10 ms 12184 KB Output is correct
31 Correct 10 ms 12184 KB Output is correct
32 Correct 11 ms 12128 KB Output is correct
33 Correct 11 ms 12180 KB Output is correct
34 Correct 12 ms 12072 KB Output is correct
35 Correct 9 ms 12108 KB Output is correct
36 Correct 9 ms 12160 KB Output is correct
37 Correct 9 ms 12184 KB Output is correct
38 Correct 9 ms 12108 KB Output is correct
39 Correct 9 ms 12108 KB Output is correct
40 Correct 10 ms 12180 KB Output is correct
41 Correct 9 ms 12180 KB Output is correct
42 Correct 11 ms 12180 KB Output is correct
43 Correct 8 ms 12108 KB Output is correct
44 Correct 10 ms 12108 KB Output is correct
45 Correct 11 ms 12108 KB Output is correct
46 Correct 10 ms 12236 KB Output is correct
47 Correct 12 ms 12108 KB Output is correct
48 Correct 11 ms 12184 KB Output is correct
49 Correct 11 ms 12124 KB Output is correct
50 Correct 10 ms 12108 KB Output is correct
51 Correct 10 ms 12180 KB Output is correct
52 Correct 10 ms 12108 KB Output is correct
53 Correct 10 ms 12180 KB Output is correct
54 Correct 10 ms 12108 KB Output is correct
55 Correct 10 ms 12108 KB Output is correct
56 Correct 10 ms 12108 KB Output is correct
57 Correct 10 ms 12244 KB Output is correct
58 Correct 11 ms 12196 KB Output is correct
59 Correct 10 ms 12068 KB Output is correct
60 Correct 11 ms 12180 KB Output is correct
61 Correct 11 ms 12108 KB Output is correct
62 Correct 10 ms 12236 KB Output is correct
63 Correct 10 ms 12108 KB Output is correct
64 Correct 265 ms 25440 KB Output is correct
65 Correct 271 ms 25496 KB Output is correct
66 Correct 256 ms 25596 KB Output is correct
67 Correct 249 ms 25660 KB Output is correct
68 Correct 246 ms 25472 KB Output is correct
69 Correct 294 ms 25680 KB Output is correct
70 Correct 256 ms 25444 KB Output is correct
71 Correct 266 ms 25664 KB Output is correct
72 Correct 247 ms 25564 KB Output is correct
73 Correct 266 ms 32112 KB Output is correct
74 Correct 321 ms 32036 KB Output is correct
75 Correct 254 ms 26700 KB Output is correct
76 Correct 272 ms 26772 KB Output is correct
77 Correct 286 ms 25676 KB Output is correct
78 Correct 259 ms 25428 KB Output is correct
79 Correct 258 ms 25540 KB Output is correct
80 Correct 271 ms 25536 KB Output is correct
81 Correct 222 ms 25640 KB Output is correct
82 Correct 244 ms 25480 KB Output is correct
83 Correct 276 ms 28588 KB Output is correct
84 Correct 260 ms 29904 KB Output is correct
85 Correct 250 ms 29604 KB Output is correct
86 Correct 270 ms 26280 KB Output is correct
87 Correct 283 ms 25944 KB Output is correct
88 Correct 262 ms 26140 KB Output is correct
89 Correct 267 ms 26136 KB Output is correct
90 Correct 238 ms 26172 KB Output is correct
91 Correct 255 ms 26204 KB Output is correct
92 Correct 239 ms 26324 KB Output is correct
93 Correct 241 ms 27564 KB Output is correct
94 Correct 234 ms 28468 KB Output is correct
95 Correct 244 ms 27740 KB Output is correct
96 Correct 240 ms 26696 KB Output is correct
97 Correct 227 ms 25888 KB Output is correct
98 Correct 247 ms 25612 KB Output is correct
99 Correct 248 ms 25584 KB Output is correct
100 Correct 243 ms 27220 KB Output is correct
101 Correct 254 ms 25916 KB Output is correct
102 Correct 237 ms 25668 KB Output is correct
103 Correct 239 ms 25812 KB Output is correct
104 Correct 223 ms 23224 KB Output is correct
105 Correct 259 ms 30088 KB Output is correct
106 Correct 184 ms 25976 KB Output is correct
107 Correct 188 ms 26080 KB Output is correct
108 Correct 254 ms 32524 KB Output is correct
109 Correct 185 ms 23060 KB Output is correct
110 Correct 259 ms 32788 KB Output is correct
111 Correct 232 ms 25472 KB Output is correct