Submission #825838

# Submission time Handle Problem Language Result Execution time Memory
825838 2023-08-15T08:45:18 Z Hakiers Power Plant (JOI20_power) C++17
100 / 100
97 ms 29884 KB
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
const int MAXN = 2e5 + 7;
vector<int> G[MAXN];
bool generator[MAXN];
int dp[MAXN][2]; 
// dp[v][1] idziemy w gore, dp[v][0] najlepszy wynik dla poddrzewa
int n;

void dfs(int v, int p){

    int sumson = 0;


    for(auto u : G[v]){
        if(u == p) continue;
        dfs(u, v);
        sumson += dp[u][1];
        dp[v][0] = max(dp[v][0], dp[u][0]); // wyniki dla poddrzew
        if(generator[v]) dp[v][0] = max(dp[v][0], dp[u][1] + 1); // jezeli jakas sciezka konczy sie w nas 
    }

     // jezeli laczymy wszystkie poddrzewa i przechodzi przez nas 
    if(generator[v]) dp[v][0] = max({dp[v][0], sumson - 1, 1});
    else dp[v][0] = max(dp[v][0], sumson);


    if(generator[v]) 
        dp[v][1] = max(sumson - 1, 1);
    else 
        dp[v][1] = sumson;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(int i = 1; i < n; i++){
        int a, b;
        cin >> a >> b;
        G[a].push_back({b});
        G[b].push_back({a});
    }

    string s;
    cin >> s;
    s = "#" + s;
    for(int i = 1; i <= n; i++)
        generator[i] = (s[i] - '0');

    dfs(1, 1);

    cout << dp[1][0] << endl;
    
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 5076 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 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 5032 KB Output is correct
9 Correct 2 ms 5028 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 5028 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 5028 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 5076 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 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 5032 KB Output is correct
9 Correct 2 ms 5028 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 5028 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 5028 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5040 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 5040 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 3 ms 5044 KB Output is correct
28 Correct 3 ms 5076 KB Output is correct
29 Correct 3 ms 5204 KB Output is correct
30 Correct 3 ms 5204 KB Output is correct
31 Correct 3 ms 5048 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 5040 KB Output is correct
35 Correct 3 ms 5040 KB Output is correct
36 Correct 3 ms 5040 KB Output is correct
37 Correct 3 ms 5076 KB Output is correct
38 Correct 3 ms 5076 KB Output is correct
39 Correct 3 ms 5076 KB Output is correct
40 Correct 3 ms 5076 KB Output is correct
41 Correct 3 ms 5076 KB Output is correct
42 Correct 3 ms 5172 KB Output is correct
43 Correct 3 ms 5044 KB Output is correct
44 Correct 3 ms 5160 KB Output is correct
45 Correct 3 ms 5076 KB Output is correct
46 Correct 3 ms 5076 KB Output is correct
47 Correct 3 ms 5076 KB Output is correct
48 Correct 3 ms 5204 KB Output is correct
49 Correct 3 ms 5204 KB Output is correct
50 Correct 4 ms 5172 KB Output is correct
51 Correct 3 ms 5076 KB Output is correct
52 Correct 3 ms 5044 KB Output is correct
53 Correct 3 ms 5048 KB Output is correct
54 Correct 3 ms 5172 KB Output is correct
55 Correct 3 ms 5076 KB Output is correct
56 Correct 2 ms 5076 KB Output is correct
57 Correct 3 ms 5204 KB Output is correct
58 Correct 3 ms 5040 KB Output is correct
59 Correct 2 ms 5076 KB Output is correct
60 Correct 3 ms 5096 KB Output is correct
61 Correct 3 ms 5076 KB Output is correct
62 Correct 3 ms 5204 KB Output is correct
63 Correct 3 ms 5024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 5076 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 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 5032 KB Output is correct
9 Correct 2 ms 5028 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 5028 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 5028 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5040 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 5040 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 3 ms 5044 KB Output is correct
28 Correct 3 ms 5076 KB Output is correct
29 Correct 3 ms 5204 KB Output is correct
30 Correct 3 ms 5204 KB Output is correct
31 Correct 3 ms 5048 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 5040 KB Output is correct
35 Correct 3 ms 5040 KB Output is correct
36 Correct 3 ms 5040 KB Output is correct
37 Correct 3 ms 5076 KB Output is correct
38 Correct 3 ms 5076 KB Output is correct
39 Correct 3 ms 5076 KB Output is correct
40 Correct 3 ms 5076 KB Output is correct
41 Correct 3 ms 5076 KB Output is correct
42 Correct 3 ms 5172 KB Output is correct
43 Correct 3 ms 5044 KB Output is correct
44 Correct 3 ms 5160 KB Output is correct
45 Correct 3 ms 5076 KB Output is correct
46 Correct 3 ms 5076 KB Output is correct
47 Correct 3 ms 5076 KB Output is correct
48 Correct 3 ms 5204 KB Output is correct
49 Correct 3 ms 5204 KB Output is correct
50 Correct 4 ms 5172 KB Output is correct
51 Correct 3 ms 5076 KB Output is correct
52 Correct 3 ms 5044 KB Output is correct
53 Correct 3 ms 5048 KB Output is correct
54 Correct 3 ms 5172 KB Output is correct
55 Correct 3 ms 5076 KB Output is correct
56 Correct 2 ms 5076 KB Output is correct
57 Correct 3 ms 5204 KB Output is correct
58 Correct 3 ms 5040 KB Output is correct
59 Correct 2 ms 5076 KB Output is correct
60 Correct 3 ms 5096 KB Output is correct
61 Correct 3 ms 5076 KB Output is correct
62 Correct 3 ms 5204 KB Output is correct
63 Correct 3 ms 5024 KB Output is correct
64 Correct 70 ms 16180 KB Output is correct
65 Correct 88 ms 16308 KB Output is correct
66 Correct 66 ms 16160 KB Output is correct
67 Correct 86 ms 16184 KB Output is correct
68 Correct 61 ms 16080 KB Output is correct
69 Correct 72 ms 16188 KB Output is correct
70 Correct 76 ms 16164 KB Output is correct
71 Correct 78 ms 16188 KB Output is correct
72 Correct 66 ms 16196 KB Output is correct
73 Correct 83 ms 28744 KB Output is correct
74 Correct 96 ms 28672 KB Output is correct
75 Correct 65 ms 16076 KB Output is correct
76 Correct 82 ms 15956 KB Output is correct
77 Correct 73 ms 15988 KB Output is correct
78 Correct 80 ms 15992 KB Output is correct
79 Correct 65 ms 15972 KB Output is correct
80 Correct 66 ms 16080 KB Output is correct
81 Correct 58 ms 16408 KB Output is correct
82 Correct 82 ms 16224 KB Output is correct
83 Correct 85 ms 21288 KB Output is correct
84 Correct 76 ms 23404 KB Output is correct
85 Correct 97 ms 23048 KB Output is correct
86 Correct 71 ms 17464 KB Output is correct
87 Correct 68 ms 16932 KB Output is correct
88 Correct 67 ms 17396 KB Output is correct
89 Correct 76 ms 17352 KB Output is correct
90 Correct 82 ms 17172 KB Output is correct
91 Correct 74 ms 17388 KB Output is correct
92 Correct 78 ms 17740 KB Output is correct
93 Correct 69 ms 20116 KB Output is correct
94 Correct 64 ms 21912 KB Output is correct
95 Correct 65 ms 20448 KB Output is correct
96 Correct 70 ms 18716 KB Output is correct
97 Correct 80 ms 17156 KB Output is correct
98 Correct 89 ms 16860 KB Output is correct
99 Correct 72 ms 16516 KB Output is correct
100 Correct 67 ms 19680 KB Output is correct
101 Correct 66 ms 17600 KB Output is correct
102 Correct 66 ms 16860 KB Output is correct
103 Correct 62 ms 16660 KB Output is correct
104 Correct 49 ms 16960 KB Output is correct
105 Correct 77 ms 25544 KB Output is correct
106 Correct 46 ms 16920 KB Output is correct
107 Correct 48 ms 16868 KB Output is correct
108 Correct 79 ms 29528 KB Output is correct
109 Correct 44 ms 16960 KB Output is correct
110 Correct 83 ms 29884 KB Output is correct
111 Correct 60 ms 16004 KB Output is correct