Submission #763189

# Submission time Handle Problem Language Result Execution time Memory
763189 2023-06-22T06:13:29 Z huutuan Power Plant (JOI20_power) C++14
100 / 100
142 ms 25000 KB
#include<bits/stdc++.h>

using namespace std;

#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define sumof(x) accumulate(all(x), 0ll)

const int N=2e5+1;
int n, a[N], f[N][2];
vector<int> g[N];

void dfs(int u, int p){
    for (int v:g[u]) if (v!=p) dfs(v, u);
    int m=0;
    for (int v:g[u]) if (v!=p){
        f[u][0]+=f[v][1];
        m=max(m, f[v][1]);
    }
    int x=f[u][0]-a[u];
    f[u][0]=max(x, a[u]+m);
    f[u][1]=max(x, a[u]);
}

void solve(int tc){
    // cout << "Case #" << tc << ": ";
    cin >> n;
    for (int i=1; i<n; ++i){
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    for (int i=1; i<=n; ++i){
        char c; cin >> c;
        a[i]=c-'0';
    }
    dfs(1, 1);
    int ans=0;
    for (int i=1; i<=n; ++i) ans=max(ans, f[i][0]);
    cout << ans;
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int ntests=1;
    // cin >> ntests;
    for (int i=1; i<=ntests; ++i) solve(i);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5028 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 3 ms 5032 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 5024 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 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 5024 KB Output is correct
15 Correct 2 ms 5024 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5028 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4996 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5028 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 3 ms 5032 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 5024 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 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 5024 KB Output is correct
15 Correct 2 ms 5024 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5028 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4996 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5204 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 5168 KB Output is correct
26 Correct 4 ms 5168 KB Output is correct
27 Correct 3 ms 5156 KB Output is correct
28 Correct 4 ms 5160 KB Output is correct
29 Correct 3 ms 5204 KB Output is correct
30 Correct 4 ms 5204 KB Output is correct
31 Correct 3 ms 5076 KB Output is correct
32 Correct 3 ms 5076 KB Output is correct
33 Correct 3 ms 5088 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5076 KB Output is correct
36 Correct 3 ms 5164 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 5168 KB Output is correct
40 Correct 3 ms 5168 KB Output is correct
41 Correct 3 ms 5204 KB Output is correct
42 Correct 4 ms 5168 KB Output is correct
43 Correct 3 ms 5204 KB Output is correct
44 Correct 3 ms 5076 KB Output is correct
45 Correct 3 ms 5076 KB Output is correct
46 Correct 3 ms 5076 KB Output is correct
47 Correct 4 ms 5164 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 5076 KB Output is correct
51 Correct 3 ms 5076 KB Output is correct
52 Correct 3 ms 5076 KB Output is correct
53 Correct 3 ms 5164 KB Output is correct
54 Correct 5 ms 5148 KB Output is correct
55 Correct 3 ms 5076 KB Output is correct
56 Correct 3 ms 5076 KB Output is correct
57 Correct 3 ms 5164 KB Output is correct
58 Correct 3 ms 5076 KB Output is correct
59 Correct 3 ms 5076 KB Output is correct
60 Correct 3 ms 5204 KB Output is correct
61 Correct 3 ms 5092 KB Output is correct
62 Correct 3 ms 5204 KB Output is correct
63 Correct 3 ms 5164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5028 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 3 ms 5032 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 5024 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 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 5024 KB Output is correct
15 Correct 2 ms 5024 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5028 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4996 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5204 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 5168 KB Output is correct
26 Correct 4 ms 5168 KB Output is correct
27 Correct 3 ms 5156 KB Output is correct
28 Correct 4 ms 5160 KB Output is correct
29 Correct 3 ms 5204 KB Output is correct
30 Correct 4 ms 5204 KB Output is correct
31 Correct 3 ms 5076 KB Output is correct
32 Correct 3 ms 5076 KB Output is correct
33 Correct 3 ms 5088 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5076 KB Output is correct
36 Correct 3 ms 5164 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 5168 KB Output is correct
40 Correct 3 ms 5168 KB Output is correct
41 Correct 3 ms 5204 KB Output is correct
42 Correct 4 ms 5168 KB Output is correct
43 Correct 3 ms 5204 KB Output is correct
44 Correct 3 ms 5076 KB Output is correct
45 Correct 3 ms 5076 KB Output is correct
46 Correct 3 ms 5076 KB Output is correct
47 Correct 4 ms 5164 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 5076 KB Output is correct
51 Correct 3 ms 5076 KB Output is correct
52 Correct 3 ms 5076 KB Output is correct
53 Correct 3 ms 5164 KB Output is correct
54 Correct 5 ms 5148 KB Output is correct
55 Correct 3 ms 5076 KB Output is correct
56 Correct 3 ms 5076 KB Output is correct
57 Correct 3 ms 5164 KB Output is correct
58 Correct 3 ms 5076 KB Output is correct
59 Correct 3 ms 5076 KB Output is correct
60 Correct 3 ms 5204 KB Output is correct
61 Correct 3 ms 5092 KB Output is correct
62 Correct 3 ms 5204 KB Output is correct
63 Correct 3 ms 5164 KB Output is correct
64 Correct 114 ms 17708 KB Output is correct
65 Correct 84 ms 17688 KB Output is correct
66 Correct 87 ms 17804 KB Output is correct
67 Correct 105 ms 17748 KB Output is correct
68 Correct 91 ms 17696 KB Output is correct
69 Correct 86 ms 17696 KB Output is correct
70 Correct 100 ms 17752 KB Output is correct
71 Correct 88 ms 17756 KB Output is correct
72 Correct 99 ms 17728 KB Output is correct
73 Correct 142 ms 24420 KB Output is correct
74 Correct 89 ms 24280 KB Output is correct
75 Correct 91 ms 18928 KB Output is correct
76 Correct 96 ms 19020 KB Output is correct
77 Correct 96 ms 17732 KB Output is correct
78 Correct 81 ms 17800 KB Output is correct
79 Correct 85 ms 17696 KB Output is correct
80 Correct 84 ms 17736 KB Output is correct
81 Correct 71 ms 17728 KB Output is correct
82 Correct 90 ms 17684 KB Output is correct
83 Correct 91 ms 20796 KB Output is correct
84 Correct 95 ms 22116 KB Output is correct
85 Correct 93 ms 21812 KB Output is correct
86 Correct 106 ms 18508 KB Output is correct
87 Correct 96 ms 18168 KB Output is correct
88 Correct 79 ms 18340 KB Output is correct
89 Correct 77 ms 18380 KB Output is correct
90 Correct 78 ms 18244 KB Output is correct
91 Correct 100 ms 18452 KB Output is correct
92 Correct 109 ms 18596 KB Output is correct
93 Correct 84 ms 19664 KB Output is correct
94 Correct 72 ms 20756 KB Output is correct
95 Correct 80 ms 19900 KB Output is correct
96 Correct 104 ms 18908 KB Output is correct
97 Correct 80 ms 18052 KB Output is correct
98 Correct 77 ms 17964 KB Output is correct
99 Correct 91 ms 17900 KB Output is correct
100 Correct 82 ms 19568 KB Output is correct
101 Correct 91 ms 18316 KB Output is correct
102 Correct 73 ms 17960 KB Output is correct
103 Correct 81 ms 18056 KB Output is correct
104 Correct 54 ms 18200 KB Output is correct
105 Correct 92 ms 22400 KB Output is correct
106 Correct 64 ms 18276 KB Output is correct
107 Correct 64 ms 18260 KB Output is correct
108 Correct 89 ms 24776 KB Output is correct
109 Correct 54 ms 18288 KB Output is correct
110 Correct 91 ms 25000 KB Output is correct
111 Correct 119 ms 17740 KB Output is correct