답안 #539008

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
539008 2022-03-18T08:21:33 Z ddy888 Power Plant (JOI20_power) C++17
100 / 100
183 ms 32324 KB
#undef _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define fi first
#define si second
#define ar array
using lint = long long;
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;  
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {cerr<<" "<<to_string(H);debug_out(T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)

int N, ans;
vector<int> adj[200010];
char S[200010];
int dp[200010][2];

void dfs(int x, int p) {
    int sum = 0, mx = 0;
    for (auto i: adj[x]) {
        if (i == p) continue;
        dfs(i, x);
        sum += dp[i][0];
        mx = max(mx, dp[i][0]);
    }
    if (S[x] == '1') {
        dp[x][1] = max(mx + 1, 1);
        dp[x][0] = max(sum - 1, 1);
    } else {
        dp[x][0] = sum;
        dp[x][1] = sum;
    }
}

int main() {
    fast;
    cin >> N;
    for (int i = 1; i < N; ++i) {
        int u, v; cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    for (int i = 1; i <= N; ++i) cin >> S[i];
    dfs(1, -1);
    for (int i = 1; i <= N; ++i) ans = max({ans, dp[i][0], dp[i][1]});
    cout << ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5036 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5032 KB Output is correct
5 Correct 3 ms 5032 KB Output is correct
6 Correct 3 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 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5028 KB Output is correct
13 Correct 3 ms 5032 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 4 ms 5028 KB Output is correct
19 Correct 3 ms 5028 KB Output is correct
20 Correct 3 ms 5036 KB Output is correct
21 Correct 3 ms 5032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5036 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5032 KB Output is correct
5 Correct 3 ms 5032 KB Output is correct
6 Correct 3 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 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5028 KB Output is correct
13 Correct 3 ms 5032 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 4 ms 5028 KB Output is correct
19 Correct 3 ms 5028 KB Output is correct
20 Correct 3 ms 5036 KB Output is correct
21 Correct 3 ms 5032 KB Output is correct
22 Correct 4 ms 5076 KB Output is correct
23 Correct 4 ms 5088 KB Output is correct
24 Correct 3 ms 5088 KB Output is correct
25 Correct 3 ms 5076 KB Output is correct
26 Correct 4 ms 5076 KB Output is correct
27 Correct 5 ms 5136 KB Output is correct
28 Correct 4 ms 5040 KB Output is correct
29 Correct 5 ms 5172 KB Output is correct
30 Correct 4 ms 5204 KB Output is correct
31 Correct 3 ms 5040 KB Output is correct
32 Correct 3 ms 5076 KB Output is correct
33 Correct 3 ms 5040 KB Output is correct
34 Correct 4 ms 5076 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 4 ms 5076 KB Output is correct
37 Correct 3 ms 5044 KB Output is correct
38 Correct 3 ms 5076 KB Output is correct
39 Correct 4 ms 5176 KB Output is correct
40 Correct 4 ms 5076 KB Output is correct
41 Correct 4 ms 5204 KB Output is correct
42 Correct 4 ms 5168 KB Output is correct
43 Correct 4 ms 5044 KB Output is correct
44 Correct 4 ms 5168 KB Output is correct
45 Correct 4 ms 5088 KB Output is correct
46 Correct 4 ms 5068 KB Output is correct
47 Correct 4 ms 5088 KB Output is correct
48 Correct 4 ms 5204 KB Output is correct
49 Correct 3 ms 5172 KB Output is correct
50 Correct 4 ms 5172 KB Output is correct
51 Correct 3 ms 5092 KB Output is correct
52 Correct 4 ms 5076 KB Output is correct
53 Correct 3 ms 5076 KB Output is correct
54 Correct 3 ms 5172 KB Output is correct
55 Correct 3 ms 5096 KB Output is correct
56 Correct 4 ms 5044 KB Output is correct
57 Correct 5 ms 5204 KB Output is correct
58 Correct 3 ms 5044 KB Output is correct
59 Correct 5 ms 5040 KB Output is correct
60 Correct 5 ms 5204 KB Output is correct
61 Correct 4 ms 5076 KB Output is correct
62 Correct 4 ms 5204 KB Output is correct
63 Correct 4 ms 5040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5036 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5032 KB Output is correct
5 Correct 3 ms 5032 KB Output is correct
6 Correct 3 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 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5028 KB Output is correct
13 Correct 3 ms 5032 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 4 ms 5028 KB Output is correct
19 Correct 3 ms 5028 KB Output is correct
20 Correct 3 ms 5036 KB Output is correct
21 Correct 3 ms 5032 KB Output is correct
22 Correct 4 ms 5076 KB Output is correct
23 Correct 4 ms 5088 KB Output is correct
24 Correct 3 ms 5088 KB Output is correct
25 Correct 3 ms 5076 KB Output is correct
26 Correct 4 ms 5076 KB Output is correct
27 Correct 5 ms 5136 KB Output is correct
28 Correct 4 ms 5040 KB Output is correct
29 Correct 5 ms 5172 KB Output is correct
30 Correct 4 ms 5204 KB Output is correct
31 Correct 3 ms 5040 KB Output is correct
32 Correct 3 ms 5076 KB Output is correct
33 Correct 3 ms 5040 KB Output is correct
34 Correct 4 ms 5076 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 4 ms 5076 KB Output is correct
37 Correct 3 ms 5044 KB Output is correct
38 Correct 3 ms 5076 KB Output is correct
39 Correct 4 ms 5176 KB Output is correct
40 Correct 4 ms 5076 KB Output is correct
41 Correct 4 ms 5204 KB Output is correct
42 Correct 4 ms 5168 KB Output is correct
43 Correct 4 ms 5044 KB Output is correct
44 Correct 4 ms 5168 KB Output is correct
45 Correct 4 ms 5088 KB Output is correct
46 Correct 4 ms 5068 KB Output is correct
47 Correct 4 ms 5088 KB Output is correct
48 Correct 4 ms 5204 KB Output is correct
49 Correct 3 ms 5172 KB Output is correct
50 Correct 4 ms 5172 KB Output is correct
51 Correct 3 ms 5092 KB Output is correct
52 Correct 4 ms 5076 KB Output is correct
53 Correct 3 ms 5076 KB Output is correct
54 Correct 3 ms 5172 KB Output is correct
55 Correct 3 ms 5096 KB Output is correct
56 Correct 4 ms 5044 KB Output is correct
57 Correct 5 ms 5204 KB Output is correct
58 Correct 3 ms 5044 KB Output is correct
59 Correct 5 ms 5040 KB Output is correct
60 Correct 5 ms 5204 KB Output is correct
61 Correct 4 ms 5076 KB Output is correct
62 Correct 4 ms 5204 KB Output is correct
63 Correct 4 ms 5040 KB Output is correct
64 Correct 159 ms 15840 KB Output is correct
65 Correct 136 ms 15876 KB Output is correct
66 Correct 152 ms 15908 KB Output is correct
67 Correct 156 ms 15892 KB Output is correct
68 Correct 132 ms 15864 KB Output is correct
69 Correct 145 ms 15744 KB Output is correct
70 Correct 144 ms 15812 KB Output is correct
71 Correct 155 ms 15800 KB Output is correct
72 Correct 145 ms 15872 KB Output is correct
73 Correct 169 ms 31004 KB Output is correct
74 Correct 172 ms 30952 KB Output is correct
75 Correct 142 ms 15792 KB Output is correct
76 Correct 145 ms 15676 KB Output is correct
77 Correct 161 ms 15748 KB Output is correct
78 Correct 144 ms 15868 KB Output is correct
79 Correct 165 ms 15740 KB Output is correct
80 Correct 141 ms 15664 KB Output is correct
81 Correct 118 ms 16152 KB Output is correct
82 Correct 138 ms 15912 KB Output is correct
83 Correct 136 ms 21968 KB Output is correct
84 Correct 149 ms 24568 KB Output is correct
85 Correct 177 ms 24140 KB Output is correct
86 Correct 126 ms 17376 KB Output is correct
87 Correct 143 ms 16752 KB Output is correct
88 Correct 152 ms 17212 KB Output is correct
89 Correct 143 ms 17244 KB Output is correct
90 Correct 135 ms 16884 KB Output is correct
91 Correct 137 ms 17228 KB Output is correct
92 Correct 148 ms 17624 KB Output is correct
93 Correct 120 ms 20556 KB Output is correct
94 Correct 112 ms 22492 KB Output is correct
95 Correct 112 ms 20988 KB Output is correct
96 Correct 165 ms 18868 KB Output is correct
97 Correct 113 ms 17108 KB Output is correct
98 Correct 114 ms 16332 KB Output is correct
99 Correct 116 ms 16156 KB Output is correct
100 Correct 131 ms 19968 KB Output is correct
101 Correct 152 ms 17740 KB Output is correct
102 Correct 156 ms 16580 KB Output is correct
103 Correct 137 ms 16368 KB Output is correct
104 Correct 84 ms 16548 KB Output is correct
105 Correct 183 ms 27092 KB Output is correct
106 Correct 70 ms 16400 KB Output is correct
107 Correct 87 ms 16348 KB Output is correct
108 Correct 151 ms 31960 KB Output is correct
109 Correct 88 ms 16676 KB Output is correct
110 Correct 148 ms 32324 KB Output is correct
111 Correct 121 ms 15680 KB Output is correct