답안 #763014

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
763014 2023-06-22T02:26:10 Z adaawf Power Plant (JOI20_power) C++14
100 / 100
175 ms 34780 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 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 5004 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 5 ms 4936 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 3 ms 4948 KB Output is correct
15 Correct 3 ms 5004 KB Output is correct
16 Correct 2 ms 5000 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 2 ms 5000 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 5004 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 5 ms 4936 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 3 ms 4948 KB Output is correct
15 Correct 3 ms 5004 KB Output is correct
16 Correct 2 ms 5000 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 2 ms 5000 KB Output is correct
21 Correct 2 ms 4948 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 5140 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 5140 KB Output is correct
28 Correct 4 ms 5076 KB Output is correct
29 Correct 5 ms 5272 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 5144 KB Output is correct
33 Correct 4 ms 5076 KB Output is correct
34 Correct 4 ms 5076 KB Output is correct
35 Correct 3 ms 5068 KB Output is correct
36 Correct 3 ms 5144 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 5200 KB Output is correct
40 Correct 3 ms 5144 KB Output is correct
41 Correct 3 ms 5200 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 5140 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 5076 KB Output is correct
48 Correct 4 ms 5140 KB Output is correct
49 Correct 4 ms 5204 KB Output is correct
50 Correct 3 ms 5076 KB Output is correct
51 Correct 3 ms 5144 KB Output is correct
52 Correct 3 ms 5072 KB Output is correct
53 Correct 3 ms 5076 KB Output is correct
54 Correct 3 ms 5144 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 5272 KB Output is correct
58 Correct 3 ms 5076 KB Output is correct
59 Correct 3 ms 5076 KB Output is correct
60 Correct 4 ms 5144 KB Output is correct
61 Correct 3 ms 5076 KB Output is correct
62 Correct 3 ms 5272 KB Output is correct
63 Correct 3 ms 5148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 5004 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 5 ms 4936 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 3 ms 4948 KB Output is correct
15 Correct 3 ms 5004 KB Output is correct
16 Correct 2 ms 5000 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 2 ms 5000 KB Output is correct
21 Correct 2 ms 4948 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 5140 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 5140 KB Output is correct
28 Correct 4 ms 5076 KB Output is correct
29 Correct 5 ms 5272 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 5144 KB Output is correct
33 Correct 4 ms 5076 KB Output is correct
34 Correct 4 ms 5076 KB Output is correct
35 Correct 3 ms 5068 KB Output is correct
36 Correct 3 ms 5144 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 5200 KB Output is correct
40 Correct 3 ms 5144 KB Output is correct
41 Correct 3 ms 5200 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 5140 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 5076 KB Output is correct
48 Correct 4 ms 5140 KB Output is correct
49 Correct 4 ms 5204 KB Output is correct
50 Correct 3 ms 5076 KB Output is correct
51 Correct 3 ms 5144 KB Output is correct
52 Correct 3 ms 5072 KB Output is correct
53 Correct 3 ms 5076 KB Output is correct
54 Correct 3 ms 5144 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 5272 KB Output is correct
58 Correct 3 ms 5076 KB Output is correct
59 Correct 3 ms 5076 KB Output is correct
60 Correct 4 ms 5144 KB Output is correct
61 Correct 3 ms 5076 KB Output is correct
62 Correct 3 ms 5272 KB Output is correct
63 Correct 3 ms 5148 KB Output is correct
64 Correct 138 ms 19040 KB Output is correct
65 Correct 153 ms 19108 KB Output is correct
66 Correct 134 ms 19028 KB Output is correct
67 Correct 153 ms 19096 KB Output is correct
68 Correct 139 ms 19020 KB Output is correct
69 Correct 157 ms 19224 KB Output is correct
70 Correct 136 ms 18984 KB Output is correct
71 Correct 136 ms 19100 KB Output is correct
72 Correct 132 ms 18284 KB Output is correct
73 Correct 164 ms 34260 KB Output is correct
74 Correct 156 ms 34160 KB Output is correct
75 Correct 133 ms 18884 KB Output is correct
76 Correct 138 ms 18964 KB Output is correct
77 Correct 164 ms 18872 KB Output is correct
78 Correct 136 ms 18872 KB Output is correct
79 Correct 152 ms 18968 KB Output is correct
80 Correct 137 ms 18972 KB Output is correct
81 Correct 141 ms 19452 KB Output is correct
82 Correct 130 ms 19084 KB Output is correct
83 Correct 146 ms 25132 KB Output is correct
84 Correct 148 ms 27796 KB Output is correct
85 Correct 175 ms 27420 KB Output is correct
86 Correct 136 ms 20632 KB Output is correct
87 Correct 141 ms 19992 KB Output is correct
88 Correct 134 ms 20380 KB Output is correct
89 Correct 156 ms 20544 KB Output is correct
90 Correct 150 ms 20100 KB Output is correct
91 Correct 150 ms 20488 KB Output is correct
92 Correct 139 ms 20864 KB Output is correct
93 Correct 154 ms 23716 KB Output is correct
94 Correct 132 ms 25880 KB Output is correct
95 Correct 138 ms 24164 KB Output is correct
96 Correct 137 ms 22112 KB Output is correct
97 Correct 138 ms 20260 KB Output is correct
98 Correct 133 ms 19560 KB Output is correct
99 Correct 135 ms 19400 KB Output is correct
100 Correct 136 ms 23148 KB Output is correct
101 Correct 151 ms 20952 KB Output is correct
102 Correct 148 ms 19868 KB Output is correct
103 Correct 133 ms 19660 KB Output is correct
104 Correct 115 ms 19164 KB Output is correct
105 Correct 164 ms 29588 KB Output is correct
106 Correct 107 ms 19672 KB Output is correct
107 Correct 117 ms 19776 KB Output is correct
108 Correct 147 ms 34328 KB Output is correct
109 Correct 117 ms 19224 KB Output is correct
110 Correct 152 ms 34780 KB Output is correct
111 Correct 129 ms 18924 KB Output is correct