Submission #795148

# Submission time Handle Problem Language Result Execution time Memory
795148 2023-07-27T07:03:44 Z raysh07 Power Plant (JOI20_power) C++17
100 / 100
211 ms 33936 KB
#include<bits/stdc++.h>
 
using namespace std;
#define int long long
 
const int MAX_N = 2*1e5;
int n, dp[MAX_N][2];
string s;
vector<int> adj[MAX_N];
 
void find_dp(int id, int anc){
    dp[id][0]= 0;
    dp[id][1] = 0;
 
    bool gen = s[id] == '1';
 
    int s1=0;
    int best1= 0;
    int best0= 0;
 
    for(auto e: adj[id]){
        if(e!=anc){
            find_dp(e, id);
            s1 += dp[e][1];
            best1 = max(best1, dp[e][1]);
            best0 = max(best0, dp[e][0]);
        }
    }
    if(!gen){
        dp[id][0] = max(max(s1, best0), 0LL);
        dp[id][1] = max(s1, 0LL);
    }
    else{
        dp[id][0] = max(s1-1, max(best1+1, best0));
        dp[id][1] = max(s1-1, 1LL);
    }
 
    //cout<<id<<" "<<dp[id][0]<<" "<<dp[id][1]<<endl;
}
 
 
signed main(){
    cin>>n;
 
    for(int i = 0; i<n-1; i++){
        int a, b;
        cin>>a>>b;
        a--;b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
 
    cin>>s;
 
    find_dp(0, -1);
    cout<<dp[0][0]<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4892 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 2 ms 4928 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 5008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4892 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 2 ms 4928 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 5008 KB Output is correct
22 Correct 4 ms 5076 KB Output is correct
23 Correct 4 ms 5076 KB Output is correct
24 Correct 5 ms 5080 KB Output is correct
25 Correct 5 ms 5120 KB Output is correct
26 Correct 4 ms 5148 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 3 ms 5076 KB Output is correct
29 Correct 3 ms 5280 KB Output is correct
30 Correct 3 ms 5204 KB Output is correct
31 Correct 3 ms 5076 KB Output is correct
32 Correct 3 ms 5076 KB Output is correct
33 Correct 3 ms 5076 KB Output is correct
34 Correct 3 ms 5076 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 5 ms 5016 KB Output is correct
37 Correct 4 ms 5080 KB Output is correct
38 Correct 5 ms 5076 KB Output is correct
39 Correct 4 ms 5204 KB Output is correct
40 Correct 3 ms 5076 KB Output is correct
41 Correct 4 ms 5204 KB Output is correct
42 Correct 3 ms 5076 KB Output is correct
43 Correct 3 ms 5076 KB Output is correct
44 Correct 4 ms 5204 KB Output is correct
45 Correct 4 ms 5076 KB Output is correct
46 Correct 3 ms 5076 KB Output is correct
47 Correct 4 ms 5148 KB Output is correct
48 Correct 3 ms 5204 KB Output is correct
49 Correct 3 ms 5204 KB Output is correct
50 Correct 3 ms 5144 KB Output is correct
51 Correct 3 ms 5076 KB Output is correct
52 Correct 4 ms 5148 KB Output is correct
53 Correct 3 ms 5076 KB Output is correct
54 Correct 3 ms 5076 KB Output is correct
55 Correct 3 ms 5076 KB Output is correct
56 Correct 3 ms 5148 KB Output is correct
57 Correct 3 ms 5204 KB Output is correct
58 Correct 3 ms 5144 KB Output is correct
59 Correct 3 ms 5148 KB Output is correct
60 Correct 4 ms 5204 KB Output is correct
61 Correct 3 ms 5076 KB Output is correct
62 Correct 4 ms 5204 KB Output is correct
63 Correct 3 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4892 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 2 ms 4928 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 5008 KB Output is correct
22 Correct 4 ms 5076 KB Output is correct
23 Correct 4 ms 5076 KB Output is correct
24 Correct 5 ms 5080 KB Output is correct
25 Correct 5 ms 5120 KB Output is correct
26 Correct 4 ms 5148 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 3 ms 5076 KB Output is correct
29 Correct 3 ms 5280 KB Output is correct
30 Correct 3 ms 5204 KB Output is correct
31 Correct 3 ms 5076 KB Output is correct
32 Correct 3 ms 5076 KB Output is correct
33 Correct 3 ms 5076 KB Output is correct
34 Correct 3 ms 5076 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 5 ms 5016 KB Output is correct
37 Correct 4 ms 5080 KB Output is correct
38 Correct 5 ms 5076 KB Output is correct
39 Correct 4 ms 5204 KB Output is correct
40 Correct 3 ms 5076 KB Output is correct
41 Correct 4 ms 5204 KB Output is correct
42 Correct 3 ms 5076 KB Output is correct
43 Correct 3 ms 5076 KB Output is correct
44 Correct 4 ms 5204 KB Output is correct
45 Correct 4 ms 5076 KB Output is correct
46 Correct 3 ms 5076 KB Output is correct
47 Correct 4 ms 5148 KB Output is correct
48 Correct 3 ms 5204 KB Output is correct
49 Correct 3 ms 5204 KB Output is correct
50 Correct 3 ms 5144 KB Output is correct
51 Correct 3 ms 5076 KB Output is correct
52 Correct 4 ms 5148 KB Output is correct
53 Correct 3 ms 5076 KB Output is correct
54 Correct 3 ms 5076 KB Output is correct
55 Correct 3 ms 5076 KB Output is correct
56 Correct 3 ms 5148 KB Output is correct
57 Correct 3 ms 5204 KB Output is correct
58 Correct 3 ms 5144 KB Output is correct
59 Correct 3 ms 5148 KB Output is correct
60 Correct 4 ms 5204 KB Output is correct
61 Correct 3 ms 5076 KB Output is correct
62 Correct 4 ms 5204 KB Output is correct
63 Correct 3 ms 5076 KB Output is correct
64 Correct 156 ms 18520 KB Output is correct
65 Correct 143 ms 18504 KB Output is correct
66 Correct 146 ms 18460 KB Output is correct
67 Correct 162 ms 18668 KB Output is correct
68 Correct 176 ms 18420 KB Output is correct
69 Correct 155 ms 18508 KB Output is correct
70 Correct 168 ms 18408 KB Output is correct
71 Correct 151 ms 18424 KB Output is correct
72 Correct 139 ms 18416 KB Output is correct
73 Correct 202 ms 32684 KB Output is correct
74 Correct 167 ms 32564 KB Output is correct
75 Correct 156 ms 19648 KB Output is correct
76 Correct 147 ms 19644 KB Output is correct
77 Correct 139 ms 18468 KB Output is correct
78 Correct 146 ms 18496 KB Output is correct
79 Correct 150 ms 18492 KB Output is correct
80 Correct 145 ms 18444 KB Output is correct
81 Correct 155 ms 18584 KB Output is correct
82 Correct 145 ms 18456 KB Output is correct
83 Correct 162 ms 24580 KB Output is correct
84 Correct 197 ms 27084 KB Output is correct
85 Correct 175 ms 26840 KB Output is correct
86 Correct 151 ms 20140 KB Output is correct
87 Correct 145 ms 19328 KB Output is correct
88 Correct 161 ms 19468 KB Output is correct
89 Correct 146 ms 19516 KB Output is correct
90 Correct 151 ms 19340 KB Output is correct
91 Correct 156 ms 19528 KB Output is correct
92 Correct 154 ms 19880 KB Output is correct
93 Correct 146 ms 22708 KB Output is correct
94 Correct 156 ms 24712 KB Output is correct
95 Correct 143 ms 23120 KB Output is correct
96 Correct 147 ms 20960 KB Output is correct
97 Correct 135 ms 19144 KB Output is correct
98 Correct 153 ms 18664 KB Output is correct
99 Correct 140 ms 18604 KB Output is correct
100 Correct 141 ms 22104 KB Output is correct
101 Correct 140 ms 19676 KB Output is correct
102 Correct 153 ms 18980 KB Output is correct
103 Correct 188 ms 18724 KB Output is correct
104 Correct 122 ms 19160 KB Output is correct
105 Correct 163 ms 28784 KB Output is correct
106 Correct 130 ms 19132 KB Output is correct
107 Correct 114 ms 18908 KB Output is correct
108 Correct 159 ms 33592 KB Output is correct
109 Correct 130 ms 19200 KB Output is correct
110 Correct 211 ms 33936 KB Output is correct
111 Correct 149 ms 18460 KB Output is correct