Submission #1084793

# Submission time Handle Problem Language Result Execution time Memory
1084793 2024-09-07T02:33:34 Z anhthi Power Plant (JOI20_power) C++14
100 / 100
81 ms 31652 KB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define ll long long
#define mp(x, y) make_pair(x, y)
#define sz(v) ((int) (v).size())
#define all(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define BIT(x, y) (((x) >> (y)) & 1)
#define pb push_back
#define max_rng *max_element
#define min_rng *min_element
#define rep(i, n) for(int i = 1, _n = (n); i <= _n; ++i)
#define forn(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define ford(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)

template <class X, class Y>
    inline bool maximize(X &x, Y y) {
        return (x < y ? x = y, true : false);
    }

template <class X, class Y>
    inline bool minimize(X &x, Y y) {
        return (x > y ? x = y, true : false);
    }

template <class X>
    inline void compress(vector<X> &a) {
        sort(all(a));
        a.resize(unique(all(a)) - a.begin());
    }

int ctz(ll x) { return __builtin_ctzll(x); }
int lg(ll x) { return 63 - __builtin_clzll(x); }
int popcount(ll x) { return __builtin_popcount(x); }

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) {
    return l + abs((ll) rng()) % (r - l + 1);
}

const ll oo = (ll) 1e17;
const int inf = (ll) 2e9 + 7, mod = (ll) 1e9 + 7;

const int mxn = 2e5, mxm = 3e6;
const int LG = 18, BASE = 311;

int n;
char s[mxn + 5];
vector<int> g[mxn + 5];

int ans = 0;
int f[mxn + 5];

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

int main(void) {

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> n;
    rep(i, n-1) {
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    rep(i, n) cin >> s[i];

    dfs();
    cout << ans;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 3 ms 4952 KB Output is correct
19 Correct 2 ms 5164 KB Output is correct
20 Correct 2 ms 4952 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 3 ms 4952 KB Output is correct
19 Correct 2 ms 5164 KB Output is correct
20 Correct 2 ms 4952 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 3 ms 5212 KB Output is correct
23 Correct 4 ms 5212 KB Output is correct
24 Correct 2 ms 5180 KB Output is correct
25 Correct 2 ms 5212 KB Output is correct
26 Correct 2 ms 5212 KB Output is correct
27 Correct 2 ms 5212 KB Output is correct
28 Correct 2 ms 5212 KB Output is correct
29 Correct 4 ms 5208 KB Output is correct
30 Correct 3 ms 5212 KB Output is correct
31 Correct 2 ms 5212 KB Output is correct
32 Correct 4 ms 5212 KB Output is correct
33 Correct 3 ms 5180 KB Output is correct
34 Correct 3 ms 5208 KB Output is correct
35 Correct 3 ms 5212 KB Output is correct
36 Correct 3 ms 5180 KB Output is correct
37 Correct 2 ms 5212 KB Output is correct
38 Correct 3 ms 5212 KB Output is correct
39 Correct 3 ms 5212 KB Output is correct
40 Correct 3 ms 5212 KB Output is correct
41 Correct 3 ms 5212 KB Output is correct
42 Correct 3 ms 5212 KB Output is correct
43 Correct 3 ms 5212 KB Output is correct
44 Correct 4 ms 5248 KB Output is correct
45 Correct 2 ms 5212 KB Output is correct
46 Correct 3 ms 5212 KB Output is correct
47 Correct 3 ms 5184 KB Output is correct
48 Correct 2 ms 5176 KB Output is correct
49 Correct 3 ms 5208 KB Output is correct
50 Correct 3 ms 5208 KB Output is correct
51 Correct 3 ms 5212 KB Output is correct
52 Correct 3 ms 5236 KB Output is correct
53 Correct 2 ms 5212 KB Output is correct
54 Correct 2 ms 5212 KB Output is correct
55 Correct 3 ms 5212 KB Output is correct
56 Correct 2 ms 5212 KB Output is correct
57 Correct 3 ms 5208 KB Output is correct
58 Correct 2 ms 5212 KB Output is correct
59 Correct 3 ms 5208 KB Output is correct
60 Correct 4 ms 5212 KB Output is correct
61 Correct 2 ms 5212 KB Output is correct
62 Correct 2 ms 5212 KB Output is correct
63 Correct 2 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 3 ms 4952 KB Output is correct
19 Correct 2 ms 5164 KB Output is correct
20 Correct 2 ms 4952 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 3 ms 5212 KB Output is correct
23 Correct 4 ms 5212 KB Output is correct
24 Correct 2 ms 5180 KB Output is correct
25 Correct 2 ms 5212 KB Output is correct
26 Correct 2 ms 5212 KB Output is correct
27 Correct 2 ms 5212 KB Output is correct
28 Correct 2 ms 5212 KB Output is correct
29 Correct 4 ms 5208 KB Output is correct
30 Correct 3 ms 5212 KB Output is correct
31 Correct 2 ms 5212 KB Output is correct
32 Correct 4 ms 5212 KB Output is correct
33 Correct 3 ms 5180 KB Output is correct
34 Correct 3 ms 5208 KB Output is correct
35 Correct 3 ms 5212 KB Output is correct
36 Correct 3 ms 5180 KB Output is correct
37 Correct 2 ms 5212 KB Output is correct
38 Correct 3 ms 5212 KB Output is correct
39 Correct 3 ms 5212 KB Output is correct
40 Correct 3 ms 5212 KB Output is correct
41 Correct 3 ms 5212 KB Output is correct
42 Correct 3 ms 5212 KB Output is correct
43 Correct 3 ms 5212 KB Output is correct
44 Correct 4 ms 5248 KB Output is correct
45 Correct 2 ms 5212 KB Output is correct
46 Correct 3 ms 5212 KB Output is correct
47 Correct 3 ms 5184 KB Output is correct
48 Correct 2 ms 5176 KB Output is correct
49 Correct 3 ms 5208 KB Output is correct
50 Correct 3 ms 5208 KB Output is correct
51 Correct 3 ms 5212 KB Output is correct
52 Correct 3 ms 5236 KB Output is correct
53 Correct 2 ms 5212 KB Output is correct
54 Correct 2 ms 5212 KB Output is correct
55 Correct 3 ms 5212 KB Output is correct
56 Correct 2 ms 5212 KB Output is correct
57 Correct 3 ms 5208 KB Output is correct
58 Correct 2 ms 5212 KB Output is correct
59 Correct 3 ms 5208 KB Output is correct
60 Correct 4 ms 5212 KB Output is correct
61 Correct 2 ms 5212 KB Output is correct
62 Correct 2 ms 5212 KB Output is correct
63 Correct 2 ms 5212 KB Output is correct
64 Correct 58 ms 15212 KB Output is correct
65 Correct 58 ms 15184 KB Output is correct
66 Correct 62 ms 15132 KB Output is correct
67 Correct 60 ms 15100 KB Output is correct
68 Correct 58 ms 15188 KB Output is correct
69 Correct 66 ms 15188 KB Output is correct
70 Correct 57 ms 15184 KB Output is correct
71 Correct 57 ms 15188 KB Output is correct
72 Correct 60 ms 15016 KB Output is correct
73 Correct 76 ms 30288 KB Output is correct
74 Correct 81 ms 30292 KB Output is correct
75 Correct 63 ms 14932 KB Output is correct
76 Correct 62 ms 14928 KB Output is correct
77 Correct 57 ms 14928 KB Output is correct
78 Correct 58 ms 14932 KB Output is correct
79 Correct 57 ms 14928 KB Output is correct
80 Correct 58 ms 14928 KB Output is correct
81 Correct 55 ms 15304 KB Output is correct
82 Correct 55 ms 15308 KB Output is correct
83 Correct 68 ms 21328 KB Output is correct
84 Correct 73 ms 23892 KB Output is correct
85 Correct 61 ms 23436 KB Output is correct
86 Correct 58 ms 16724 KB Output is correct
87 Correct 62 ms 16008 KB Output is correct
88 Correct 67 ms 16464 KB Output is correct
89 Correct 60 ms 16588 KB Output is correct
90 Correct 56 ms 16212 KB Output is correct
91 Correct 67 ms 16508 KB Output is correct
92 Correct 59 ms 16980 KB Output is correct
93 Correct 59 ms 19848 KB Output is correct
94 Correct 57 ms 21704 KB Output is correct
95 Correct 57 ms 20172 KB Output is correct
96 Correct 60 ms 18256 KB Output is correct
97 Correct 56 ms 16292 KB Output is correct
98 Correct 55 ms 15780 KB Output is correct
99 Correct 72 ms 15324 KB Output is correct
100 Correct 58 ms 19284 KB Output is correct
101 Correct 62 ms 16952 KB Output is correct
102 Correct 57 ms 15956 KB Output is correct
103 Correct 57 ms 15700 KB Output is correct
104 Correct 39 ms 15048 KB Output is correct
105 Correct 70 ms 26448 KB Output is correct
106 Correct 43 ms 15772 KB Output is correct
107 Correct 43 ms 15556 KB Output is correct
108 Correct 75 ms 31060 KB Output is correct
109 Correct 52 ms 15048 KB Output is correct
110 Correct 73 ms 31652 KB Output is correct
111 Correct 57 ms 14932 KB Output is correct