Submission #320589

# Submission time Handle Problem Language Result Execution time Memory
320589 2020-11-09T07:56:40 Z achibasadzishvili Power Plant (JOI20_power) C++14
100 / 100
217 ms 37864 KB
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
using namespace std;
ll dp[300005][2],n,c[300005];
vector<ll>v[300005];
void go(ll x,ll par){
    ll mx0 = 0,mx1 = 0,sum0 = 0,sum1 = 0;
    for(int i=0; i<v[x].size(); i++){
        int to = v[x][i];
        if(to == par)continue;
        go(to , x);
        mx0 = max(mx0 , dp[to][0]);
        sum0 += dp[to][0];
        sum1 += dp[to][1];
        mx1 = max(mx1 , dp[to][1]);
    }
    mx0 = max(mx0 , c[x] + mx1);
    dp[x][0] = mx0;
    dp[x][1] = max(c[x] , sum1 - c[x]);
}
int main(){
    ios::sync_with_stdio(false);
    cin >> n;
    
    for(int i=1; i<n; i++){
        ll x,y;
        cin >> x >> y;
        v[x].pb(y);
        v[y].pb(x);
    }
    
    for(int i=1; i<=n; i++){
        char x;
        cin >> x;
        c[i] = (x == '1');
    }
    
    go(1 , 0);
    
    cout << max(dp[1][0] , dp[1][1]) << '\n';
    
    
    
    return 0;
}

Compilation message

power.cpp: In function 'void go(long long int, long long int)':
power.cpp:11:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for(int i=0; i<v[x].size(); i++){
      |                  ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 5 ms 7532 KB Output is correct
3 Correct 5 ms 7404 KB Output is correct
4 Correct 5 ms 7404 KB Output is correct
5 Correct 6 ms 7404 KB Output is correct
6 Correct 5 ms 7404 KB Output is correct
7 Correct 5 ms 7404 KB Output is correct
8 Correct 5 ms 7404 KB Output is correct
9 Correct 5 ms 7404 KB Output is correct
10 Correct 5 ms 7404 KB Output is correct
11 Correct 5 ms 7404 KB Output is correct
12 Correct 5 ms 7404 KB Output is correct
13 Correct 5 ms 7404 KB Output is correct
14 Correct 5 ms 7552 KB Output is correct
15 Correct 5 ms 7404 KB Output is correct
16 Correct 5 ms 7404 KB Output is correct
17 Correct 5 ms 7532 KB Output is correct
18 Correct 5 ms 7404 KB Output is correct
19 Correct 5 ms 7404 KB Output is correct
20 Correct 5 ms 7404 KB Output is correct
21 Correct 5 ms 7404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 5 ms 7532 KB Output is correct
3 Correct 5 ms 7404 KB Output is correct
4 Correct 5 ms 7404 KB Output is correct
5 Correct 6 ms 7404 KB Output is correct
6 Correct 5 ms 7404 KB Output is correct
7 Correct 5 ms 7404 KB Output is correct
8 Correct 5 ms 7404 KB Output is correct
9 Correct 5 ms 7404 KB Output is correct
10 Correct 5 ms 7404 KB Output is correct
11 Correct 5 ms 7404 KB Output is correct
12 Correct 5 ms 7404 KB Output is correct
13 Correct 5 ms 7404 KB Output is correct
14 Correct 5 ms 7552 KB Output is correct
15 Correct 5 ms 7404 KB Output is correct
16 Correct 5 ms 7404 KB Output is correct
17 Correct 5 ms 7532 KB Output is correct
18 Correct 5 ms 7404 KB Output is correct
19 Correct 5 ms 7404 KB Output is correct
20 Correct 5 ms 7404 KB Output is correct
21 Correct 5 ms 7404 KB Output is correct
22 Correct 6 ms 7532 KB Output is correct
23 Correct 6 ms 7532 KB Output is correct
24 Correct 6 ms 7532 KB Output is correct
25 Correct 6 ms 7532 KB Output is correct
26 Correct 5 ms 7532 KB Output is correct
27 Correct 8 ms 7532 KB Output is correct
28 Correct 6 ms 7532 KB Output is correct
29 Correct 6 ms 7660 KB Output is correct
30 Correct 7 ms 7680 KB Output is correct
31 Correct 6 ms 7532 KB Output is correct
32 Correct 7 ms 7532 KB Output is correct
33 Correct 6 ms 7532 KB Output is correct
34 Correct 6 ms 7532 KB Output is correct
35 Correct 6 ms 7532 KB Output is correct
36 Correct 6 ms 7532 KB Output is correct
37 Correct 6 ms 7532 KB Output is correct
38 Correct 5 ms 7532 KB Output is correct
39 Correct 7 ms 7804 KB Output is correct
40 Correct 6 ms 7532 KB Output is correct
41 Correct 6 ms 7660 KB Output is correct
42 Correct 6 ms 7532 KB Output is correct
43 Correct 7 ms 7532 KB Output is correct
44 Correct 6 ms 7532 KB Output is correct
45 Correct 6 ms 7532 KB Output is correct
46 Correct 5 ms 7532 KB Output is correct
47 Correct 6 ms 7532 KB Output is correct
48 Correct 7 ms 7660 KB Output is correct
49 Correct 6 ms 7660 KB Output is correct
50 Correct 6 ms 7532 KB Output is correct
51 Correct 6 ms 7532 KB Output is correct
52 Correct 6 ms 7532 KB Output is correct
53 Correct 6 ms 7532 KB Output is correct
54 Correct 6 ms 7532 KB Output is correct
55 Correct 6 ms 7532 KB Output is correct
56 Correct 5 ms 7532 KB Output is correct
57 Correct 6 ms 7660 KB Output is correct
58 Correct 6 ms 7532 KB Output is correct
59 Correct 6 ms 7532 KB Output is correct
60 Correct 6 ms 7660 KB Output is correct
61 Correct 5 ms 7532 KB Output is correct
62 Correct 5 ms 7660 KB Output is correct
63 Correct 5 ms 7532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 5 ms 7532 KB Output is correct
3 Correct 5 ms 7404 KB Output is correct
4 Correct 5 ms 7404 KB Output is correct
5 Correct 6 ms 7404 KB Output is correct
6 Correct 5 ms 7404 KB Output is correct
7 Correct 5 ms 7404 KB Output is correct
8 Correct 5 ms 7404 KB Output is correct
9 Correct 5 ms 7404 KB Output is correct
10 Correct 5 ms 7404 KB Output is correct
11 Correct 5 ms 7404 KB Output is correct
12 Correct 5 ms 7404 KB Output is correct
13 Correct 5 ms 7404 KB Output is correct
14 Correct 5 ms 7552 KB Output is correct
15 Correct 5 ms 7404 KB Output is correct
16 Correct 5 ms 7404 KB Output is correct
17 Correct 5 ms 7532 KB Output is correct
18 Correct 5 ms 7404 KB Output is correct
19 Correct 5 ms 7404 KB Output is correct
20 Correct 5 ms 7404 KB Output is correct
21 Correct 5 ms 7404 KB Output is correct
22 Correct 6 ms 7532 KB Output is correct
23 Correct 6 ms 7532 KB Output is correct
24 Correct 6 ms 7532 KB Output is correct
25 Correct 6 ms 7532 KB Output is correct
26 Correct 5 ms 7532 KB Output is correct
27 Correct 8 ms 7532 KB Output is correct
28 Correct 6 ms 7532 KB Output is correct
29 Correct 6 ms 7660 KB Output is correct
30 Correct 7 ms 7680 KB Output is correct
31 Correct 6 ms 7532 KB Output is correct
32 Correct 7 ms 7532 KB Output is correct
33 Correct 6 ms 7532 KB Output is correct
34 Correct 6 ms 7532 KB Output is correct
35 Correct 6 ms 7532 KB Output is correct
36 Correct 6 ms 7532 KB Output is correct
37 Correct 6 ms 7532 KB Output is correct
38 Correct 5 ms 7532 KB Output is correct
39 Correct 7 ms 7804 KB Output is correct
40 Correct 6 ms 7532 KB Output is correct
41 Correct 6 ms 7660 KB Output is correct
42 Correct 6 ms 7532 KB Output is correct
43 Correct 7 ms 7532 KB Output is correct
44 Correct 6 ms 7532 KB Output is correct
45 Correct 6 ms 7532 KB Output is correct
46 Correct 5 ms 7532 KB Output is correct
47 Correct 6 ms 7532 KB Output is correct
48 Correct 7 ms 7660 KB Output is correct
49 Correct 6 ms 7660 KB Output is correct
50 Correct 6 ms 7532 KB Output is correct
51 Correct 6 ms 7532 KB Output is correct
52 Correct 6 ms 7532 KB Output is correct
53 Correct 6 ms 7532 KB Output is correct
54 Correct 6 ms 7532 KB Output is correct
55 Correct 6 ms 7532 KB Output is correct
56 Correct 5 ms 7532 KB Output is correct
57 Correct 6 ms 7660 KB Output is correct
58 Correct 6 ms 7532 KB Output is correct
59 Correct 6 ms 7532 KB Output is correct
60 Correct 6 ms 7660 KB Output is correct
61 Correct 5 ms 7532 KB Output is correct
62 Correct 5 ms 7660 KB Output is correct
63 Correct 5 ms 7532 KB Output is correct
64 Correct 182 ms 22244 KB Output is correct
65 Correct 185 ms 22372 KB Output is correct
66 Correct 209 ms 22244 KB Output is correct
67 Correct 197 ms 22244 KB Output is correct
68 Correct 182 ms 22116 KB Output is correct
69 Correct 190 ms 22116 KB Output is correct
70 Correct 190 ms 22120 KB Output is correct
71 Correct 191 ms 22372 KB Output is correct
72 Correct 195 ms 22168 KB Output is correct
73 Correct 214 ms 36324 KB Output is correct
74 Correct 197 ms 36324 KB Output is correct
75 Correct 186 ms 23396 KB Output is correct
76 Correct 181 ms 23396 KB Output is correct
77 Correct 188 ms 22396 KB Output is correct
78 Correct 196 ms 22244 KB Output is correct
79 Correct 206 ms 22244 KB Output is correct
80 Correct 185 ms 22272 KB Output is correct
81 Correct 149 ms 22104 KB Output is correct
82 Correct 162 ms 22108 KB Output is correct
83 Correct 192 ms 28260 KB Output is correct
84 Correct 217 ms 30820 KB Output is correct
85 Correct 214 ms 30564 KB Output is correct
86 Correct 182 ms 23780 KB Output is correct
87 Correct 195 ms 23140 KB Output is correct
88 Correct 164 ms 23144 KB Output is correct
89 Correct 170 ms 23268 KB Output is correct
90 Correct 170 ms 22884 KB Output is correct
91 Correct 165 ms 23268 KB Output is correct
92 Correct 186 ms 23652 KB Output is correct
93 Correct 169 ms 26460 KB Output is correct
94 Correct 153 ms 28252 KB Output is correct
95 Correct 164 ms 26840 KB Output is correct
96 Correct 160 ms 24676 KB Output is correct
97 Correct 166 ms 23012 KB Output is correct
98 Correct 167 ms 22372 KB Output is correct
99 Correct 168 ms 22244 KB Output is correct
100 Correct 167 ms 25828 KB Output is correct
101 Correct 159 ms 23396 KB Output is correct
102 Correct 164 ms 22500 KB Output is correct
103 Correct 180 ms 22500 KB Output is correct
104 Correct 107 ms 22808 KB Output is correct
105 Correct 194 ms 32484 KB Output is correct
106 Correct 112 ms 22656 KB Output is correct
107 Correct 107 ms 22608 KB Output is correct
108 Correct 196 ms 37348 KB Output is correct
109 Correct 111 ms 22880 KB Output is correct
110 Correct 211 ms 37864 KB Output is correct
111 Correct 163 ms 22116 KB Output is correct