Submission #868677

# Submission time Handle Problem Language Result Execution time Memory
868677 2023-11-01T12:03:13 Z sleepntsheep Power Plant (JOI20_power) C++17
100 / 100
89 ms 29268 KB
#include <cstdio>
#include <cstring>
#include <cassert>
#include <string>
#include <deque>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <iostream>
#include <utility>
using namespace std;
using ll = long long;
using ld = long double;
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false)

#define N 200005
#define ALL(x) x.begin(), x.end()

int n, ans, f[N], h[N], pwr[N];
vector<int> g[N];
char s[N];

void dfs(int u, int p)
{
    for (auto v:g[u]) if(v-p)
    {
        dfs(v, u);
        if(s[u]=='1')f[u]+=f[v],h[u]=max(h[u],f[v]+1);
        else f[u]+=max(f[v],h[v]-2),h[u]=max(h[u],f[v]);
    }
    if(s[u]=='1')f[u]=max(1,f[u]-1),h[u]=max(h[u],1);
    ans=max({ans,f[u],h[u]});
}


int main()
{
    ShinLena;
    cin >> n;
    for (int i = 1, u, v; i < n; ++i) cin >> u >> v, g[u].push_back(v), g[v].push_back(u);
    cin >> (s+1);
    dfs(1, 0);
    cout<<ans;

    return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6648 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6488 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6744 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6648 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6488 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6744 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6620 KB Output is correct
22 Correct 2 ms 6488 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 2 ms 6492 KB Output is correct
25 Correct 2 ms 6492 KB Output is correct
26 Correct 2 ms 6492 KB Output is correct
27 Correct 2 ms 6492 KB Output is correct
28 Correct 2 ms 6488 KB Output is correct
29 Correct 2 ms 6744 KB Output is correct
30 Correct 2 ms 6748 KB Output is correct
31 Correct 2 ms 6492 KB Output is correct
32 Correct 2 ms 6492 KB Output is correct
33 Correct 2 ms 6492 KB Output is correct
34 Correct 2 ms 6492 KB Output is correct
35 Correct 2 ms 6692 KB Output is correct
36 Correct 2 ms 6632 KB Output is correct
37 Correct 2 ms 6656 KB Output is correct
38 Correct 2 ms 6628 KB Output is correct
39 Correct 2 ms 6632 KB Output is correct
40 Correct 2 ms 6748 KB Output is correct
41 Correct 2 ms 6748 KB Output is correct
42 Correct 2 ms 6492 KB Output is correct
43 Correct 2 ms 6632 KB Output is correct
44 Correct 2 ms 6748 KB Output is correct
45 Correct 2 ms 6748 KB Output is correct
46 Correct 2 ms 6492 KB Output is correct
47 Correct 2 ms 6580 KB Output is correct
48 Correct 2 ms 6748 KB Output is correct
49 Correct 2 ms 6748 KB Output is correct
50 Correct 2 ms 6744 KB Output is correct
51 Correct 2 ms 6744 KB Output is correct
52 Correct 2 ms 6488 KB Output is correct
53 Correct 2 ms 6632 KB Output is correct
54 Correct 2 ms 6492 KB Output is correct
55 Correct 2 ms 6492 KB Output is correct
56 Correct 2 ms 6492 KB Output is correct
57 Correct 2 ms 6748 KB Output is correct
58 Correct 2 ms 6488 KB Output is correct
59 Correct 2 ms 6492 KB Output is correct
60 Correct 2 ms 6744 KB Output is correct
61 Correct 1 ms 6492 KB Output is correct
62 Correct 2 ms 6748 KB Output is correct
63 Correct 2 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6648 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6488 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6744 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6620 KB Output is correct
22 Correct 2 ms 6488 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 2 ms 6492 KB Output is correct
25 Correct 2 ms 6492 KB Output is correct
26 Correct 2 ms 6492 KB Output is correct
27 Correct 2 ms 6492 KB Output is correct
28 Correct 2 ms 6488 KB Output is correct
29 Correct 2 ms 6744 KB Output is correct
30 Correct 2 ms 6748 KB Output is correct
31 Correct 2 ms 6492 KB Output is correct
32 Correct 2 ms 6492 KB Output is correct
33 Correct 2 ms 6492 KB Output is correct
34 Correct 2 ms 6492 KB Output is correct
35 Correct 2 ms 6692 KB Output is correct
36 Correct 2 ms 6632 KB Output is correct
37 Correct 2 ms 6656 KB Output is correct
38 Correct 2 ms 6628 KB Output is correct
39 Correct 2 ms 6632 KB Output is correct
40 Correct 2 ms 6748 KB Output is correct
41 Correct 2 ms 6748 KB Output is correct
42 Correct 2 ms 6492 KB Output is correct
43 Correct 2 ms 6632 KB Output is correct
44 Correct 2 ms 6748 KB Output is correct
45 Correct 2 ms 6748 KB Output is correct
46 Correct 2 ms 6492 KB Output is correct
47 Correct 2 ms 6580 KB Output is correct
48 Correct 2 ms 6748 KB Output is correct
49 Correct 2 ms 6748 KB Output is correct
50 Correct 2 ms 6744 KB Output is correct
51 Correct 2 ms 6744 KB Output is correct
52 Correct 2 ms 6488 KB Output is correct
53 Correct 2 ms 6632 KB Output is correct
54 Correct 2 ms 6492 KB Output is correct
55 Correct 2 ms 6492 KB Output is correct
56 Correct 2 ms 6492 KB Output is correct
57 Correct 2 ms 6748 KB Output is correct
58 Correct 2 ms 6488 KB Output is correct
59 Correct 2 ms 6492 KB Output is correct
60 Correct 2 ms 6744 KB Output is correct
61 Correct 1 ms 6492 KB Output is correct
62 Correct 2 ms 6748 KB Output is correct
63 Correct 2 ms 6492 KB Output is correct
64 Correct 78 ms 15468 KB Output is correct
65 Correct 67 ms 15440 KB Output is correct
66 Correct 58 ms 15584 KB Output is correct
67 Correct 64 ms 15416 KB Output is correct
68 Correct 57 ms 15444 KB Output is correct
69 Correct 73 ms 15440 KB Output is correct
70 Correct 61 ms 15444 KB Output is correct
71 Correct 55 ms 15448 KB Output is correct
72 Correct 65 ms 15352 KB Output is correct
73 Correct 79 ms 27980 KB Output is correct
74 Correct 73 ms 28024 KB Output is correct
75 Correct 63 ms 15444 KB Output is correct
76 Correct 54 ms 15440 KB Output is correct
77 Correct 58 ms 15232 KB Output is correct
78 Correct 57 ms 15424 KB Output is correct
79 Correct 77 ms 15472 KB Output is correct
80 Correct 59 ms 15440 KB Output is correct
81 Correct 51 ms 15816 KB Output is correct
82 Correct 58 ms 15568 KB Output is correct
83 Correct 75 ms 20564 KB Output is correct
84 Correct 75 ms 22596 KB Output is correct
85 Correct 70 ms 22504 KB Output is correct
86 Correct 61 ms 16720 KB Output is correct
87 Correct 59 ms 16140 KB Output is correct
88 Correct 74 ms 16976 KB Output is correct
89 Correct 61 ms 16976 KB Output is correct
90 Correct 58 ms 16468 KB Output is correct
91 Correct 64 ms 16828 KB Output is correct
92 Correct 89 ms 17004 KB Output is correct
93 Correct 73 ms 19548 KB Output is correct
94 Correct 59 ms 21192 KB Output is correct
95 Correct 67 ms 19920 KB Output is correct
96 Correct 58 ms 18256 KB Output is correct
97 Correct 59 ms 16468 KB Output is correct
98 Correct 57 ms 16124 KB Output is correct
99 Correct 73 ms 15696 KB Output is correct
100 Correct 63 ms 19024 KB Output is correct
101 Correct 60 ms 17096 KB Output is correct
102 Correct 53 ms 16212 KB Output is correct
103 Correct 86 ms 15948 KB Output is correct
104 Correct 42 ms 15516 KB Output is correct
105 Correct 74 ms 24920 KB Output is correct
106 Correct 39 ms 16068 KB Output is correct
107 Correct 39 ms 16068 KB Output is correct
108 Correct 76 ms 28960 KB Output is correct
109 Correct 54 ms 15556 KB Output is correct
110 Correct 78 ms 29268 KB Output is correct
111 Correct 51 ms 15444 KB Output is correct