답안 #411278

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
411278 2021-05-24T21:53:36 Z nichke Power Plant (JOI20_power) C++14
100 / 100
211 ms 31272 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'

int n;
int cnt;
string s;

vector<int> adj[200005];
bool pw[200005];
int dp[200005][2];

void dfs(int v, int p = -1) {
	if (s[v] == '1') dp[v][0] = 1;
	int tot = 0, mx = 0;
	for (int u : adj[v]) {
		if (u == p) continue;
		dfs(u, v);
		tot += dp[u][0];
		mx = max(mx, dp[u][0]);
	}
	dp[v][0] = max(tot - dp[v][0], dp[v][0]);
	if (s[v] == '1') dp[v][1] = mx + 1;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int i = 1; i < n; i++) {
		int u, v; cin >> u >> v;
		u--; v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	cin >> s;
	for (int i = 0; i < n; i++) {
		if (s[i] == '1') cnt++;
	}
	int ans = 0;
	dfs(0);
	for (int i = 0; i < n; i++) {
		ans = max({ans, dp[i][0], dp[i][1]});
	}
	cout << ans << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 5056 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 4 ms 4960 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 5056 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 4 ms 4960 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 4 ms 5068 KB Output is correct
23 Correct 4 ms 5068 KB Output is correct
24 Correct 4 ms 5068 KB Output is correct
25 Correct 4 ms 5108 KB Output is correct
26 Correct 4 ms 5068 KB Output is correct
27 Correct 4 ms 5068 KB Output is correct
28 Correct 4 ms 5068 KB Output is correct
29 Correct 4 ms 5196 KB Output is correct
30 Correct 4 ms 5084 KB Output is correct
31 Correct 4 ms 5068 KB Output is correct
32 Correct 4 ms 5084 KB Output is correct
33 Correct 4 ms 5068 KB Output is correct
34 Correct 4 ms 5068 KB Output is correct
35 Correct 4 ms 5080 KB Output is correct
36 Correct 4 ms 5068 KB Output is correct
37 Correct 4 ms 5068 KB Output is correct
38 Correct 5 ms 5068 KB Output is correct
39 Correct 4 ms 5068 KB Output is correct
40 Correct 4 ms 5156 KB Output is correct
41 Correct 4 ms 5068 KB Output is correct
42 Correct 4 ms 5068 KB Output is correct
43 Correct 4 ms 5068 KB Output is correct
44 Correct 4 ms 5068 KB Output is correct
45 Correct 4 ms 5068 KB Output is correct
46 Correct 4 ms 5068 KB Output is correct
47 Correct 4 ms 5068 KB Output is correct
48 Correct 4 ms 5196 KB Output is correct
49 Correct 4 ms 5068 KB Output is correct
50 Correct 4 ms 5068 KB Output is correct
51 Correct 4 ms 5068 KB Output is correct
52 Correct 4 ms 5068 KB Output is correct
53 Correct 4 ms 5068 KB Output is correct
54 Correct 4 ms 5068 KB Output is correct
55 Correct 4 ms 5068 KB Output is correct
56 Correct 4 ms 5068 KB Output is correct
57 Correct 4 ms 5196 KB Output is correct
58 Correct 4 ms 5068 KB Output is correct
59 Correct 4 ms 5068 KB Output is correct
60 Correct 4 ms 5168 KB Output is correct
61 Correct 4 ms 5068 KB Output is correct
62 Correct 4 ms 5196 KB Output is correct
63 Correct 4 ms 5068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 5056 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 4 ms 4960 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 4 ms 5068 KB Output is correct
23 Correct 4 ms 5068 KB Output is correct
24 Correct 4 ms 5068 KB Output is correct
25 Correct 4 ms 5108 KB Output is correct
26 Correct 4 ms 5068 KB Output is correct
27 Correct 4 ms 5068 KB Output is correct
28 Correct 4 ms 5068 KB Output is correct
29 Correct 4 ms 5196 KB Output is correct
30 Correct 4 ms 5084 KB Output is correct
31 Correct 4 ms 5068 KB Output is correct
32 Correct 4 ms 5084 KB Output is correct
33 Correct 4 ms 5068 KB Output is correct
34 Correct 4 ms 5068 KB Output is correct
35 Correct 4 ms 5080 KB Output is correct
36 Correct 4 ms 5068 KB Output is correct
37 Correct 4 ms 5068 KB Output is correct
38 Correct 5 ms 5068 KB Output is correct
39 Correct 4 ms 5068 KB Output is correct
40 Correct 4 ms 5156 KB Output is correct
41 Correct 4 ms 5068 KB Output is correct
42 Correct 4 ms 5068 KB Output is correct
43 Correct 4 ms 5068 KB Output is correct
44 Correct 4 ms 5068 KB Output is correct
45 Correct 4 ms 5068 KB Output is correct
46 Correct 4 ms 5068 KB Output is correct
47 Correct 4 ms 5068 KB Output is correct
48 Correct 4 ms 5196 KB Output is correct
49 Correct 4 ms 5068 KB Output is correct
50 Correct 4 ms 5068 KB Output is correct
51 Correct 4 ms 5068 KB Output is correct
52 Correct 4 ms 5068 KB Output is correct
53 Correct 4 ms 5068 KB Output is correct
54 Correct 4 ms 5068 KB Output is correct
55 Correct 4 ms 5068 KB Output is correct
56 Correct 4 ms 5068 KB Output is correct
57 Correct 4 ms 5196 KB Output is correct
58 Correct 4 ms 5068 KB Output is correct
59 Correct 4 ms 5068 KB Output is correct
60 Correct 4 ms 5168 KB Output is correct
61 Correct 4 ms 5068 KB Output is correct
62 Correct 4 ms 5196 KB Output is correct
63 Correct 4 ms 5068 KB Output is correct
64 Correct 148 ms 18444 KB Output is correct
65 Correct 142 ms 18528 KB Output is correct
66 Correct 143 ms 18540 KB Output is correct
67 Correct 158 ms 18432 KB Output is correct
68 Correct 147 ms 18508 KB Output is correct
69 Correct 141 ms 18548 KB Output is correct
70 Correct 145 ms 18428 KB Output is correct
71 Correct 145 ms 18440 KB Output is correct
72 Correct 147 ms 18532 KB Output is correct
73 Correct 153 ms 30152 KB Output is correct
74 Correct 157 ms 30092 KB Output is correct
75 Correct 157 ms 19748 KB Output is correct
76 Correct 149 ms 19660 KB Output is correct
77 Correct 149 ms 18448 KB Output is correct
78 Correct 146 ms 18432 KB Output is correct
79 Correct 147 ms 18408 KB Output is correct
80 Correct 149 ms 18524 KB Output is correct
81 Correct 132 ms 18536 KB Output is correct
82 Correct 143 ms 18532 KB Output is correct
83 Correct 171 ms 23512 KB Output is correct
84 Correct 157 ms 25768 KB Output is correct
85 Correct 153 ms 25324 KB Output is correct
86 Correct 169 ms 19772 KB Output is correct
87 Correct 145 ms 19264 KB Output is correct
88 Correct 139 ms 19404 KB Output is correct
89 Correct 138 ms 19396 KB Output is correct
90 Correct 131 ms 19164 KB Output is correct
91 Correct 135 ms 19432 KB Output is correct
92 Correct 152 ms 19704 KB Output is correct
93 Correct 211 ms 21932 KB Output is correct
94 Correct 134 ms 23604 KB Output is correct
95 Correct 131 ms 22324 KB Output is correct
96 Correct 166 ms 20464 KB Output is correct
97 Correct 144 ms 19024 KB Output is correct
98 Correct 131 ms 18760 KB Output is correct
99 Correct 151 ms 18544 KB Output is correct
100 Correct 140 ms 21452 KB Output is correct
101 Correct 132 ms 19420 KB Output is correct
102 Correct 129 ms 18768 KB Output is correct
103 Correct 138 ms 18796 KB Output is correct
104 Correct 101 ms 19156 KB Output is correct
105 Correct 157 ms 26952 KB Output is correct
106 Correct 119 ms 19060 KB Output is correct
107 Correct 108 ms 19040 KB Output is correct
108 Correct 154 ms 31108 KB Output is correct
109 Correct 96 ms 19192 KB Output is correct
110 Correct 156 ms 31272 KB Output is correct
111 Correct 130 ms 18452 KB Output is correct