답안 #763015

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
763015 2023-06-22T02:26:34 Z vjudge1 Power Plant (JOI20_power) C++17
100 / 100
166 ms 31968 KB
#include <iostream>
#include <vector>
using namespace std;
vector<int> g[200005];
int a[200005], f[200005][5];
void dfs(int x, int p) {
    int c = 0, d = 0, ma = 0, ma2 = 0;
    for (int w : g[x]) {
        if (w == p) continue;
        dfs(w, x);
        c += f[w][1];
        ma = max(ma, max(f[w][0], f[w][1]));
        ma2 = max(ma2, f[w][1]);
    }
    d = c;
    f[x][1] = max(a[x], c - a[x]);
    if (x == 1 && g[x].size() > 1) c -= a[x];
    else if (g[x].size() > 2) c -= a[x];
    c = max(c, ma);
    if (x == 1 && g[x].size() > 1) d -= a[x];
    else if (g[x].size() > 2) d -= a[x];
    ma2 += a[x];
    ma2 = max(ma2, d);
    f[x][0] = max(ma2, c);
}
int main() {
    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;
    s = " " + s;
    for (int i = 1; i <= n; i++) {
        if (s[i] == '1') a[i] = 1;
    }
    dfs(1, -1);
    cout << max(f[1][0], f[1][1]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 2 ms 4948 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 2 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 3 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 2 ms 4948 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 2 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 3 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 4 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 5076 KB Output is correct
29 Correct 3 ms 5204 KB Output is correct
30 Correct 3 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 5076 KB Output is correct
34 Correct 4 ms 5076 KB Output is correct
35 Correct 3 ms 5076 KB Output is correct
36 Correct 3 ms 5076 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 5076 KB Output is correct
40 Correct 3 ms 5180 KB Output is correct
41 Correct 3 ms 5076 KB Output is correct
42 Correct 3 ms 5076 KB Output is correct
43 Correct 4 ms 5076 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 3 ms 5032 KB Output is correct
48 Correct 3 ms 5204 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 5076 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 5148 KB Output is correct
56 Correct 3 ms 5076 KB Output is correct
57 Correct 3 ms 5204 KB Output is correct
58 Correct 3 ms 5088 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 5076 KB Output is correct
62 Correct 3 ms 5204 KB Output is correct
63 Correct 3 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 2 ms 4948 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 2 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 3 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 4 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 5076 KB Output is correct
29 Correct 3 ms 5204 KB Output is correct
30 Correct 3 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 5076 KB Output is correct
34 Correct 4 ms 5076 KB Output is correct
35 Correct 3 ms 5076 KB Output is correct
36 Correct 3 ms 5076 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 5076 KB Output is correct
40 Correct 3 ms 5180 KB Output is correct
41 Correct 3 ms 5076 KB Output is correct
42 Correct 3 ms 5076 KB Output is correct
43 Correct 4 ms 5076 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 3 ms 5032 KB Output is correct
48 Correct 3 ms 5204 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 5076 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 5148 KB Output is correct
56 Correct 3 ms 5076 KB Output is correct
57 Correct 3 ms 5204 KB Output is correct
58 Correct 3 ms 5088 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 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 133 ms 16344 KB Output is correct
65 Correct 135 ms 16336 KB Output is correct
66 Correct 144 ms 16368 KB Output is correct
67 Correct 138 ms 16280 KB Output is correct
68 Correct 134 ms 16312 KB Output is correct
69 Correct 130 ms 16264 KB Output is correct
70 Correct 131 ms 16304 KB Output is correct
71 Correct 134 ms 16376 KB Output is correct
72 Correct 150 ms 15672 KB Output is correct
73 Correct 152 ms 31508 KB Output is correct
74 Correct 149 ms 31440 KB Output is correct
75 Correct 138 ms 16248 KB Output is correct
76 Correct 149 ms 16176 KB Output is correct
77 Correct 145 ms 16256 KB Output is correct
78 Correct 137 ms 16216 KB Output is correct
79 Correct 139 ms 16152 KB Output is correct
80 Correct 150 ms 16252 KB Output is correct
81 Correct 123 ms 16752 KB Output is correct
82 Correct 126 ms 16320 KB Output is correct
83 Correct 140 ms 22428 KB Output is correct
84 Correct 163 ms 25172 KB Output is correct
85 Correct 166 ms 24636 KB Output is correct
86 Correct 133 ms 17944 KB Output is correct
87 Correct 142 ms 17296 KB Output is correct
88 Correct 138 ms 17688 KB Output is correct
89 Correct 135 ms 17652 KB Output is correct
90 Correct 134 ms 17428 KB Output is correct
91 Correct 132 ms 17712 KB Output is correct
92 Correct 141 ms 18076 KB Output is correct
93 Correct 134 ms 21140 KB Output is correct
94 Correct 132 ms 23236 KB Output is correct
95 Correct 140 ms 21488 KB Output is correct
96 Correct 135 ms 19364 KB Output is correct
97 Correct 134 ms 17464 KB Output is correct
98 Correct 128 ms 16952 KB Output is correct
99 Correct 148 ms 16688 KB Output is correct
100 Correct 134 ms 20488 KB Output is correct
101 Correct 133 ms 18096 KB Output is correct
102 Correct 131 ms 17104 KB Output is correct
103 Correct 131 ms 16916 KB Output is correct
104 Correct 109 ms 16384 KB Output is correct
105 Correct 161 ms 26848 KB Output is correct
106 Correct 108 ms 17060 KB Output is correct
107 Correct 108 ms 17108 KB Output is correct
108 Correct 150 ms 31652 KB Output is correct
109 Correct 114 ms 16384 KB Output is correct
110 Correct 153 ms 31968 KB Output is correct
111 Correct 125 ms 16256 KB Output is correct