Submission #766024

# Submission time Handle Problem Language Result Execution time Memory
766024 2023-06-25T08:58:22 Z Owen11 Power Plant (JOI20_power) C++14
100 / 100
119 ms 31376 KB
#include <bits/stdc++.h>
using namespace std;

# define int long long
# define fir first
# define sec second
# define pb push_back

const int cnst = 2e5+5;
bool mutipletestcase = 0;
//bool debug = false;

vector<int> vec[cnst];
bool id[cnst];
int par[cnst];
int counts[cnst];
int ans = 0;

void dfs(int x) {
    int y = 0;
    int fre = 0;
    int mx = 0;
    for(auto v: vec[x]) {
        if(v == par[x]) continue;
        par[v] = x;
        dfs(v);
        y += counts[v];
        mx = max(mx, counts[v]);
        if(counts[v]) fre++;
    }

    if(!id[x]) counts[x] = y;
    else counts[x] = max(y-1, 1ll); 
    
    if(fre == 1) ans = max(ans, y+id[x]);
    else ans = max({ans, y-id[x], mx+1});
}

void solve() {
    int n; cin >> n;

    for(int i = 1; i<n; i++) {
        int a, b; cin >> a >> b;
        vec[a].pb(b);
        vec[b].pb(a);
    }

    string s; cin >> s;

    for(int i = 0; i<n; i++) {
        id[i+1] = (s[i] == '1');
    }

    dfs(1);

    cout << ans << endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    int t = 1;
    if(mutipletestcase) cin >> t; 
    while(t--) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 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 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 5028 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 3 ms 5020 KB Output is correct
11 Correct 7 ms 4976 KB Output is correct
12 Correct 3 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 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 5024 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 5028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 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 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 5028 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 3 ms 5020 KB Output is correct
11 Correct 7 ms 4976 KB Output is correct
12 Correct 3 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 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 5024 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 5028 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5076 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 5076 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 3 ms 5164 KB Output is correct
29 Correct 3 ms 5204 KB Output is correct
30 Correct 3 ms 5164 KB Output is correct
31 Correct 3 ms 5136 KB Output is correct
32 Correct 4 ms 5172 KB Output is correct
33 Correct 3 ms 5076 KB Output is correct
34 Correct 3 ms 5088 KB Output is correct
35 Correct 3 ms 5076 KB Output is correct
36 Correct 4 ms 5076 KB Output is correct
37 Correct 3 ms 5076 KB Output is correct
38 Correct 3 ms 5132 KB Output is correct
39 Correct 3 ms 5132 KB Output is correct
40 Correct 3 ms 5076 KB Output is correct
41 Correct 3 ms 5164 KB Output is correct
42 Correct 3 ms 5088 KB Output is correct
43 Correct 3 ms 5076 KB Output is correct
44 Correct 4 ms 5164 KB Output is correct
45 Correct 3 ms 5168 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 5148 KB Output is correct
49 Correct 3 ms 5204 KB Output is correct
50 Correct 3 ms 5076 KB Output is correct
51 Correct 3 ms 5160 KB Output is correct
52 Correct 3 ms 5076 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 5164 KB Output is correct
57 Correct 3 ms 5204 KB Output is correct
58 Correct 3 ms 5076 KB Output is correct
59 Correct 3 ms 5168 KB Output is correct
60 Correct 3 ms 5204 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 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 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 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 5028 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 3 ms 5020 KB Output is correct
11 Correct 7 ms 4976 KB Output is correct
12 Correct 3 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 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 5024 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 5028 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5076 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 5076 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 3 ms 5164 KB Output is correct
29 Correct 3 ms 5204 KB Output is correct
30 Correct 3 ms 5164 KB Output is correct
31 Correct 3 ms 5136 KB Output is correct
32 Correct 4 ms 5172 KB Output is correct
33 Correct 3 ms 5076 KB Output is correct
34 Correct 3 ms 5088 KB Output is correct
35 Correct 3 ms 5076 KB Output is correct
36 Correct 4 ms 5076 KB Output is correct
37 Correct 3 ms 5076 KB Output is correct
38 Correct 3 ms 5132 KB Output is correct
39 Correct 3 ms 5132 KB Output is correct
40 Correct 3 ms 5076 KB Output is correct
41 Correct 3 ms 5164 KB Output is correct
42 Correct 3 ms 5088 KB Output is correct
43 Correct 3 ms 5076 KB Output is correct
44 Correct 4 ms 5164 KB Output is correct
45 Correct 3 ms 5168 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 5148 KB Output is correct
49 Correct 3 ms 5204 KB Output is correct
50 Correct 3 ms 5076 KB Output is correct
51 Correct 3 ms 5160 KB Output is correct
52 Correct 3 ms 5076 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 5164 KB Output is correct
57 Correct 3 ms 5204 KB Output is correct
58 Correct 3 ms 5076 KB Output is correct
59 Correct 3 ms 5168 KB Output is correct
60 Correct 3 ms 5204 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 5076 KB Output is correct
64 Correct 96 ms 18672 KB Output is correct
65 Correct 90 ms 18728 KB Output is correct
66 Correct 78 ms 18732 KB Output is correct
67 Correct 73 ms 18604 KB Output is correct
68 Correct 80 ms 18684 KB Output is correct
69 Correct 78 ms 18644 KB Output is correct
70 Correct 97 ms 18896 KB Output is correct
71 Correct 110 ms 18704 KB Output is correct
72 Correct 87 ms 18628 KB Output is correct
73 Correct 96 ms 30352 KB Output is correct
74 Correct 88 ms 30304 KB Output is correct
75 Correct 108 ms 19884 KB Output is correct
76 Correct 93 ms 19844 KB Output is correct
77 Correct 77 ms 18636 KB Output is correct
78 Correct 70 ms 18656 KB Output is correct
79 Correct 94 ms 18712 KB Output is correct
80 Correct 119 ms 18660 KB Output is correct
81 Correct 65 ms 18760 KB Output is correct
82 Correct 83 ms 18764 KB Output is correct
83 Correct 84 ms 23804 KB Output is correct
84 Correct 110 ms 25944 KB Output is correct
85 Correct 118 ms 25696 KB Output is correct
86 Correct 78 ms 19956 KB Output is correct
87 Correct 77 ms 19464 KB Output is correct
88 Correct 75 ms 19488 KB Output is correct
89 Correct 86 ms 19520 KB Output is correct
90 Correct 73 ms 19352 KB Output is correct
91 Correct 98 ms 19616 KB Output is correct
92 Correct 79 ms 19880 KB Output is correct
93 Correct 76 ms 22120 KB Output is correct
94 Correct 71 ms 23820 KB Output is correct
95 Correct 77 ms 22544 KB Output is correct
96 Correct 72 ms 20672 KB Output is correct
97 Correct 95 ms 19236 KB Output is correct
98 Correct 106 ms 18864 KB Output is correct
99 Correct 92 ms 18816 KB Output is correct
100 Correct 73 ms 21696 KB Output is correct
101 Correct 71 ms 19560 KB Output is correct
102 Correct 78 ms 19120 KB Output is correct
103 Correct 75 ms 18984 KB Output is correct
104 Correct 52 ms 19336 KB Output is correct
105 Correct 88 ms 27176 KB Output is correct
106 Correct 47 ms 19184 KB Output is correct
107 Correct 62 ms 19288 KB Output is correct
108 Correct 112 ms 31240 KB Output is correct
109 Correct 50 ms 19396 KB Output is correct
110 Correct 89 ms 31376 KB Output is correct
111 Correct 100 ms 18588 KB Output is correct