Submission #498908

# Submission time Handle Problem Language Result Execution time Memory
498908 2021-12-26T14:46:07 Z khoabright Power Plant (JOI20_power) C++17
100 / 100
174 ms 32388 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pii pair<int, int>
#define ff first
#define ss second
#define pb push_back
#define rep(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define rep1(i, a, b) for (int i = (int)a; i >= (int)b; --i)
#define all(x) x.begin(), x.end()

const int N = 2e5 + 5;
int dp[N], sig[N];
vector<int> g[N];

int ans = 0;

void dfs(int u, int p) {
    int sum = 0;
    for (int v : g[u]) {
        if (v == p) continue;
        dfs(v, u);
        sum += dp[v];
        ans = max(ans, dp[v] + sig[u]);
    }
    dp[u] = max(sig[u], sum - sig[u]);
    ans = max(ans, dp[u]);
}

void solve() {
    int n; cin >> n;
    for (int i = 1; i < n; ++i) {
        int u, v; cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    string s; cin >> s;
    rep(i, 1, n) sig[i] = s[i - 1] - '0';
    dfs(1, 0);
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 4 ms 5012 KB Output is correct
3 Correct 3 ms 5016 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 5024 KB Output is correct
6 Correct 3 ms 4928 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 5016 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4992 KB Output is correct
19 Correct 3 ms 5016 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 4 ms 5012 KB Output is correct
3 Correct 3 ms 5016 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 5024 KB Output is correct
6 Correct 3 ms 4928 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 5016 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4992 KB Output is correct
19 Correct 3 ms 5016 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 4 ms 5032 KB Output is correct
23 Correct 4 ms 5068 KB Output is correct
24 Correct 4 ms 5068 KB Output is correct
25 Correct 4 ms 5068 KB Output is correct
26 Correct 4 ms 5068 KB Output is correct
27 Correct 5 ms 5080 KB Output is correct
28 Correct 4 ms 5076 KB Output is correct
29 Correct 3 ms 5196 KB Output is correct
30 Correct 3 ms 5196 KB Output is correct
31 Correct 3 ms 5068 KB Output is correct
32 Correct 4 ms 5032 KB Output is correct
33 Correct 3 ms 5068 KB Output is correct
34 Correct 4 ms 5032 KB Output is correct
35 Correct 5 ms 5032 KB Output is correct
36 Correct 4 ms 5068 KB Output is correct
37 Correct 4 ms 5080 KB Output is correct
38 Correct 3 ms 5032 KB Output is correct
39 Correct 4 ms 5164 KB Output is correct
40 Correct 4 ms 5152 KB Output is correct
41 Correct 3 ms 5196 KB Output is correct
42 Correct 4 ms 5068 KB Output is correct
43 Correct 4 ms 5068 KB Output is correct
44 Correct 4 ms 5160 KB Output is correct
45 Correct 4 ms 5068 KB Output is correct
46 Correct 3 ms 5080 KB Output is correct
47 Correct 3 ms 5068 KB Output is correct
48 Correct 3 ms 5196 KB Output is correct
49 Correct 3 ms 5196 KB Output is correct
50 Correct 3 ms 5068 KB Output is correct
51 Correct 3 ms 5164 KB Output is correct
52 Correct 4 ms 5068 KB Output is correct
53 Correct 3 ms 5160 KB Output is correct
54 Correct 3 ms 5068 KB Output is correct
55 Correct 3 ms 5068 KB Output is correct
56 Correct 3 ms 5068 KB Output is correct
57 Correct 3 ms 5196 KB Output is correct
58 Correct 3 ms 5068 KB Output is correct
59 Correct 3 ms 5028 KB Output is correct
60 Correct 3 ms 5196 KB Output is correct
61 Correct 5 ms 5068 KB Output is correct
62 Correct 4 ms 5196 KB Output is correct
63 Correct 3 ms 5032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 4 ms 5012 KB Output is correct
3 Correct 3 ms 5016 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 5024 KB Output is correct
6 Correct 3 ms 4928 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 5016 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4992 KB Output is correct
19 Correct 3 ms 5016 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 4 ms 5032 KB Output is correct
23 Correct 4 ms 5068 KB Output is correct
24 Correct 4 ms 5068 KB Output is correct
25 Correct 4 ms 5068 KB Output is correct
26 Correct 4 ms 5068 KB Output is correct
27 Correct 5 ms 5080 KB Output is correct
28 Correct 4 ms 5076 KB Output is correct
29 Correct 3 ms 5196 KB Output is correct
30 Correct 3 ms 5196 KB Output is correct
31 Correct 3 ms 5068 KB Output is correct
32 Correct 4 ms 5032 KB Output is correct
33 Correct 3 ms 5068 KB Output is correct
34 Correct 4 ms 5032 KB Output is correct
35 Correct 5 ms 5032 KB Output is correct
36 Correct 4 ms 5068 KB Output is correct
37 Correct 4 ms 5080 KB Output is correct
38 Correct 3 ms 5032 KB Output is correct
39 Correct 4 ms 5164 KB Output is correct
40 Correct 4 ms 5152 KB Output is correct
41 Correct 3 ms 5196 KB Output is correct
42 Correct 4 ms 5068 KB Output is correct
43 Correct 4 ms 5068 KB Output is correct
44 Correct 4 ms 5160 KB Output is correct
45 Correct 4 ms 5068 KB Output is correct
46 Correct 3 ms 5080 KB Output is correct
47 Correct 3 ms 5068 KB Output is correct
48 Correct 3 ms 5196 KB Output is correct
49 Correct 3 ms 5196 KB Output is correct
50 Correct 3 ms 5068 KB Output is correct
51 Correct 3 ms 5164 KB Output is correct
52 Correct 4 ms 5068 KB Output is correct
53 Correct 3 ms 5160 KB Output is correct
54 Correct 3 ms 5068 KB Output is correct
55 Correct 3 ms 5068 KB Output is correct
56 Correct 3 ms 5068 KB Output is correct
57 Correct 3 ms 5196 KB Output is correct
58 Correct 3 ms 5068 KB Output is correct
59 Correct 3 ms 5028 KB Output is correct
60 Correct 3 ms 5196 KB Output is correct
61 Correct 5 ms 5068 KB Output is correct
62 Correct 4 ms 5196 KB Output is correct
63 Correct 3 ms 5032 KB Output is correct
64 Correct 136 ms 15928 KB Output is correct
65 Correct 150 ms 15896 KB Output is correct
66 Correct 131 ms 15952 KB Output is correct
67 Correct 158 ms 15984 KB Output is correct
68 Correct 129 ms 15876 KB Output is correct
69 Correct 136 ms 15980 KB Output is correct
70 Correct 144 ms 15920 KB Output is correct
71 Correct 139 ms 15912 KB Output is correct
72 Correct 135 ms 15952 KB Output is correct
73 Correct 174 ms 31020 KB Output is correct
74 Correct 151 ms 31072 KB Output is correct
75 Correct 140 ms 15800 KB Output is correct
76 Correct 112 ms 15756 KB Output is correct
77 Correct 126 ms 15848 KB Output is correct
78 Correct 139 ms 15952 KB Output is correct
79 Correct 141 ms 15844 KB Output is correct
80 Correct 139 ms 15872 KB Output is correct
81 Correct 104 ms 16188 KB Output is correct
82 Correct 108 ms 16068 KB Output is correct
83 Correct 156 ms 22176 KB Output is correct
84 Correct 151 ms 24592 KB Output is correct
85 Correct 141 ms 24232 KB Output is correct
86 Correct 129 ms 17532 KB Output is correct
87 Correct 120 ms 16864 KB Output is correct
88 Correct 111 ms 17412 KB Output is correct
89 Correct 143 ms 17276 KB Output is correct
90 Correct 129 ms 17060 KB Output is correct
91 Correct 114 ms 17268 KB Output is correct
92 Correct 118 ms 17692 KB Output is correct
93 Correct 141 ms 20676 KB Output is correct
94 Correct 109 ms 22756 KB Output is correct
95 Correct 114 ms 21112 KB Output is correct
96 Correct 139 ms 18988 KB Output is correct
97 Correct 123 ms 17160 KB Output is correct
98 Correct 128 ms 16524 KB Output is correct
99 Correct 109 ms 16364 KB Output is correct
100 Correct 116 ms 20148 KB Output is correct
101 Correct 139 ms 17776 KB Output is correct
102 Correct 99 ms 16748 KB Output is correct
103 Correct 128 ms 16468 KB Output is correct
104 Correct 68 ms 16840 KB Output is correct
105 Correct 164 ms 27224 KB Output is correct
106 Correct 73 ms 16652 KB Output is correct
107 Correct 78 ms 16648 KB Output is correct
108 Correct 163 ms 31952 KB Output is correct
109 Correct 68 ms 16788 KB Output is correct
110 Correct 154 ms 32388 KB Output is correct
111 Correct 130 ms 15772 KB Output is correct