답안 #1054976

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1054976 2024-08-12T13:37:28 Z Sharky Power Plant (JOI20_power) C++17
100 / 100
66 ms 30036 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 200005;
int n, dp[N], s[N], pa[N], ans = 1;
vector<int> adj[N];

void dfs(int u, int p) {
    for (int v : adj[u]) {
        if (v == p) continue;
        pa[v] = u;
        dfs(v, u);
        dp[u] += max(s[v], dp[v]);
        ans = max(ans, max(s[v], dp[v]) + s[u]);
    }
    dp[u] -= s[u];
    if (u != 1) ans = max(ans, dp[u] + s[pa[u]]);
    else ans = max(ans, dp[u]);
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (int i = 1; i < n; i++) {
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    for (int i = 1; i <= n; i++) {
        char c;
        cin >> c;
        s[i] = c - '0';
    }
    dfs(1, -1);
    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6744 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 1 ms 6748 KB Output is correct
11 Correct 1 ms 6748 KB Output is correct
12 Correct 1 ms 6796 KB Output is correct
13 Correct 1 ms 6748 KB Output is correct
14 Correct 1 ms 6748 KB Output is correct
15 Correct 1 ms 6748 KB Output is correct
16 Correct 1 ms 6748 KB Output is correct
17 Correct 1 ms 6748 KB Output is correct
18 Correct 1 ms 6748 KB Output is correct
19 Correct 1 ms 6748 KB Output is correct
20 Correct 1 ms 6804 KB Output is correct
21 Correct 1 ms 6744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6744 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 1 ms 6748 KB Output is correct
11 Correct 1 ms 6748 KB Output is correct
12 Correct 1 ms 6796 KB Output is correct
13 Correct 1 ms 6748 KB Output is correct
14 Correct 1 ms 6748 KB Output is correct
15 Correct 1 ms 6748 KB Output is correct
16 Correct 1 ms 6748 KB Output is correct
17 Correct 1 ms 6748 KB Output is correct
18 Correct 1 ms 6748 KB Output is correct
19 Correct 1 ms 6748 KB Output is correct
20 Correct 1 ms 6804 KB Output is correct
21 Correct 1 ms 6744 KB Output is correct
22 Correct 2 ms 6748 KB Output is correct
23 Correct 1 ms 6748 KB Output is correct
24 Correct 1 ms 6748 KB Output is correct
25 Correct 1 ms 6748 KB Output is correct
26 Correct 1 ms 6748 KB Output is correct
27 Correct 1 ms 6748 KB Output is correct
28 Correct 1 ms 6748 KB Output is correct
29 Correct 1 ms 6892 KB Output is correct
30 Correct 1 ms 6748 KB Output is correct
31 Correct 2 ms 6744 KB Output is correct
32 Correct 2 ms 6748 KB Output is correct
33 Correct 1 ms 6748 KB Output is correct
34 Correct 1 ms 6748 KB Output is correct
35 Correct 1 ms 6748 KB Output is correct
36 Correct 1 ms 6748 KB Output is correct
37 Correct 1 ms 6748 KB Output is correct
38 Correct 2 ms 6748 KB Output is correct
39 Correct 1 ms 6816 KB Output is correct
40 Correct 1 ms 6748 KB Output is correct
41 Correct 1 ms 6744 KB Output is correct
42 Correct 1 ms 6748 KB Output is correct
43 Correct 1 ms 6748 KB Output is correct
44 Correct 1 ms 6748 KB Output is correct
45 Correct 1 ms 6760 KB Output is correct
46 Correct 1 ms 6748 KB Output is correct
47 Correct 1 ms 6748 KB Output is correct
48 Correct 1 ms 6748 KB Output is correct
49 Correct 1 ms 6748 KB Output is correct
50 Correct 1 ms 6748 KB Output is correct
51 Correct 1 ms 6748 KB Output is correct
52 Correct 1 ms 6832 KB Output is correct
53 Correct 1 ms 6748 KB Output is correct
54 Correct 1 ms 6748 KB Output is correct
55 Correct 1 ms 6748 KB Output is correct
56 Correct 1 ms 6748 KB Output is correct
57 Correct 1 ms 7004 KB Output is correct
58 Correct 1 ms 6748 KB Output is correct
59 Correct 1 ms 6748 KB Output is correct
60 Correct 1 ms 6748 KB Output is correct
61 Correct 1 ms 6744 KB Output is correct
62 Correct 1 ms 6748 KB Output is correct
63 Correct 1 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6744 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 1 ms 6748 KB Output is correct
11 Correct 1 ms 6748 KB Output is correct
12 Correct 1 ms 6796 KB Output is correct
13 Correct 1 ms 6748 KB Output is correct
14 Correct 1 ms 6748 KB Output is correct
15 Correct 1 ms 6748 KB Output is correct
16 Correct 1 ms 6748 KB Output is correct
17 Correct 1 ms 6748 KB Output is correct
18 Correct 1 ms 6748 KB Output is correct
19 Correct 1 ms 6748 KB Output is correct
20 Correct 1 ms 6804 KB Output is correct
21 Correct 1 ms 6744 KB Output is correct
22 Correct 2 ms 6748 KB Output is correct
23 Correct 1 ms 6748 KB Output is correct
24 Correct 1 ms 6748 KB Output is correct
25 Correct 1 ms 6748 KB Output is correct
26 Correct 1 ms 6748 KB Output is correct
27 Correct 1 ms 6748 KB Output is correct
28 Correct 1 ms 6748 KB Output is correct
29 Correct 1 ms 6892 KB Output is correct
30 Correct 1 ms 6748 KB Output is correct
31 Correct 2 ms 6744 KB Output is correct
32 Correct 2 ms 6748 KB Output is correct
33 Correct 1 ms 6748 KB Output is correct
34 Correct 1 ms 6748 KB Output is correct
35 Correct 1 ms 6748 KB Output is correct
36 Correct 1 ms 6748 KB Output is correct
37 Correct 1 ms 6748 KB Output is correct
38 Correct 2 ms 6748 KB Output is correct
39 Correct 1 ms 6816 KB Output is correct
40 Correct 1 ms 6748 KB Output is correct
41 Correct 1 ms 6744 KB Output is correct
42 Correct 1 ms 6748 KB Output is correct
43 Correct 1 ms 6748 KB Output is correct
44 Correct 1 ms 6748 KB Output is correct
45 Correct 1 ms 6760 KB Output is correct
46 Correct 1 ms 6748 KB Output is correct
47 Correct 1 ms 6748 KB Output is correct
48 Correct 1 ms 6748 KB Output is correct
49 Correct 1 ms 6748 KB Output is correct
50 Correct 1 ms 6748 KB Output is correct
51 Correct 1 ms 6748 KB Output is correct
52 Correct 1 ms 6832 KB Output is correct
53 Correct 1 ms 6748 KB Output is correct
54 Correct 1 ms 6748 KB Output is correct
55 Correct 1 ms 6748 KB Output is correct
56 Correct 1 ms 6748 KB Output is correct
57 Correct 1 ms 7004 KB Output is correct
58 Correct 1 ms 6748 KB Output is correct
59 Correct 1 ms 6748 KB Output is correct
60 Correct 1 ms 6748 KB Output is correct
61 Correct 1 ms 6744 KB Output is correct
62 Correct 1 ms 6748 KB Output is correct
63 Correct 1 ms 6748 KB Output is correct
64 Correct 47 ms 16464 KB Output is correct
65 Correct 50 ms 16468 KB Output is correct
66 Correct 45 ms 16476 KB Output is correct
67 Correct 42 ms 16372 KB Output is correct
68 Correct 45 ms 16976 KB Output is correct
69 Correct 47 ms 16464 KB Output is correct
70 Correct 44 ms 16576 KB Output is correct
71 Correct 43 ms 16472 KB Output is correct
72 Correct 52 ms 16464 KB Output is correct
73 Correct 52 ms 29192 KB Output is correct
74 Correct 51 ms 29008 KB Output is correct
75 Correct 42 ms 16308 KB Output is correct
76 Correct 41 ms 16276 KB Output is correct
77 Correct 41 ms 16232 KB Output is correct
78 Correct 42 ms 16468 KB Output is correct
79 Correct 42 ms 16416 KB Output is correct
80 Correct 42 ms 16212 KB Output is correct
81 Correct 42 ms 16852 KB Output is correct
82 Correct 42 ms 16592 KB Output is correct
83 Correct 48 ms 21584 KB Output is correct
84 Correct 45 ms 23820 KB Output is correct
85 Correct 48 ms 23376 KB Output is correct
86 Correct 42 ms 17756 KB Output is correct
87 Correct 44 ms 17232 KB Output is correct
88 Correct 43 ms 17752 KB Output is correct
89 Correct 43 ms 17744 KB Output is correct
90 Correct 42 ms 17488 KB Output is correct
91 Correct 44 ms 17748 KB Output is correct
92 Correct 42 ms 18004 KB Output is correct
93 Correct 43 ms 20516 KB Output is correct
94 Correct 40 ms 21960 KB Output is correct
95 Correct 49 ms 20940 KB Output is correct
96 Correct 44 ms 19028 KB Output is correct
97 Correct 46 ms 17488 KB Output is correct
98 Correct 41 ms 16980 KB Output is correct
99 Correct 43 ms 16920 KB Output is correct
100 Correct 45 ms 20052 KB Output is correct
101 Correct 51 ms 18000 KB Output is correct
102 Correct 41 ms 17232 KB Output is correct
103 Correct 43 ms 16984 KB Output is correct
104 Correct 32 ms 17352 KB Output is correct
105 Correct 56 ms 25944 KB Output is correct
106 Correct 35 ms 17348 KB Output is correct
107 Correct 33 ms 16972 KB Output is correct
108 Correct 66 ms 29776 KB Output is correct
109 Correct 31 ms 17348 KB Output is correct
110 Correct 49 ms 30036 KB Output is correct
111 Correct 39 ms 16468 KB Output is correct