답안 #293915

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
293915 2020-09-08T13:44:13 Z Mlxa Power Plant (JOI20_power) C++14
100 / 100
234 ms 41932 KB
#ifdef LC
#include "pch.h"
#else
#include <bits/stdc++.h>
#endif

using namespace std;
using ll = long long;
#define int ll
#define all(x) x.begin(), x.end()
#define x first
#define y second
#define mp make_pair
#define mt make_tuple

const int N = 1e6 + 10;
int n;
int gen[N];
int dp[N];
vector<int> g[N];
int answer = 1;

void dfs(int v, int p) {
	dp[v] = -gen[v];
	for (int u : g[v]) {
		if (u == p) {
			continue;
		}
		dfs(u, v);
		dp[v] += dp[u];
	}
	dp[v] = max(dp[v], gen[v]);
	if (v != p) {
		answer = max(answer, dp[v] + gen[p]);
	}
	answer = max(answer, dp[v]);
}

signed main() {
#ifdef LC
	assert(freopen("input.txt", "r", stdin));
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int v, u, i = 0; i < n - 1; ++i) {
		cin >> v >> u;
		--v, --u;
		g[v].push_back(u);
		g[u].push_back(v);
	}
	/*
	for (int i = 0; i < n; ++i) {
		cout << i << ":\t";
		for (int j : g[i]) {
			cout << j << " ";
		}
		cout << endl;
	}
	*/
	string str;
	cin >> str;
	for (int i = 0; i < n; ++i) {
		gen[i] = str[i] == '1';
	}
	dfs(0, 0);
	cout << answer << "\n";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 16 ms 23808 KB Output is correct
4 Correct 16 ms 23808 KB Output is correct
5 Correct 16 ms 23808 KB Output is correct
6 Correct 16 ms 23808 KB Output is correct
7 Correct 16 ms 23808 KB Output is correct
8 Correct 16 ms 23808 KB Output is correct
9 Correct 16 ms 23808 KB Output is correct
10 Correct 16 ms 23808 KB Output is correct
11 Correct 16 ms 23808 KB Output is correct
12 Correct 16 ms 23808 KB Output is correct
13 Correct 16 ms 23808 KB Output is correct
14 Correct 16 ms 23808 KB Output is correct
15 Correct 16 ms 23808 KB Output is correct
16 Correct 17 ms 23808 KB Output is correct
17 Correct 16 ms 23808 KB Output is correct
18 Correct 16 ms 23808 KB Output is correct
19 Correct 16 ms 23848 KB Output is correct
20 Correct 16 ms 23808 KB Output is correct
21 Correct 17 ms 23936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 16 ms 23808 KB Output is correct
4 Correct 16 ms 23808 KB Output is correct
5 Correct 16 ms 23808 KB Output is correct
6 Correct 16 ms 23808 KB Output is correct
7 Correct 16 ms 23808 KB Output is correct
8 Correct 16 ms 23808 KB Output is correct
9 Correct 16 ms 23808 KB Output is correct
10 Correct 16 ms 23808 KB Output is correct
11 Correct 16 ms 23808 KB Output is correct
12 Correct 16 ms 23808 KB Output is correct
13 Correct 16 ms 23808 KB Output is correct
14 Correct 16 ms 23808 KB Output is correct
15 Correct 16 ms 23808 KB Output is correct
16 Correct 17 ms 23808 KB Output is correct
17 Correct 16 ms 23808 KB Output is correct
18 Correct 16 ms 23808 KB Output is correct
19 Correct 16 ms 23848 KB Output is correct
20 Correct 16 ms 23808 KB Output is correct
21 Correct 17 ms 23936 KB Output is correct
22 Correct 17 ms 23936 KB Output is correct
23 Correct 17 ms 24064 KB Output is correct
24 Correct 19 ms 23936 KB Output is correct
25 Correct 17 ms 23936 KB Output is correct
26 Correct 18 ms 23936 KB Output is correct
27 Correct 17 ms 23936 KB Output is correct
28 Correct 17 ms 23936 KB Output is correct
29 Correct 17 ms 23936 KB Output is correct
30 Correct 17 ms 23936 KB Output is correct
31 Correct 17 ms 23936 KB Output is correct
32 Correct 17 ms 23936 KB Output is correct
33 Correct 18 ms 23936 KB Output is correct
34 Correct 17 ms 23936 KB Output is correct
35 Correct 17 ms 23936 KB Output is correct
36 Correct 17 ms 23936 KB Output is correct
37 Correct 17 ms 23972 KB Output is correct
38 Correct 17 ms 23936 KB Output is correct
39 Correct 17 ms 23936 KB Output is correct
40 Correct 17 ms 23936 KB Output is correct
41 Correct 18 ms 23936 KB Output is correct
42 Correct 17 ms 23936 KB Output is correct
43 Correct 17 ms 23936 KB Output is correct
44 Correct 18 ms 23936 KB Output is correct
45 Correct 17 ms 23936 KB Output is correct
46 Correct 17 ms 23936 KB Output is correct
47 Correct 17 ms 23936 KB Output is correct
48 Correct 17 ms 23936 KB Output is correct
49 Correct 17 ms 23936 KB Output is correct
50 Correct 17 ms 23936 KB Output is correct
51 Correct 17 ms 23936 KB Output is correct
52 Correct 17 ms 23936 KB Output is correct
53 Correct 17 ms 23936 KB Output is correct
54 Correct 17 ms 23936 KB Output is correct
55 Correct 17 ms 23936 KB Output is correct
56 Correct 17 ms 23936 KB Output is correct
57 Correct 18 ms 24192 KB Output is correct
58 Correct 17 ms 23936 KB Output is correct
59 Correct 17 ms 23936 KB Output is correct
60 Correct 17 ms 23936 KB Output is correct
61 Correct 17 ms 23936 KB Output is correct
62 Correct 17 ms 23936 KB Output is correct
63 Correct 17 ms 23936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 16 ms 23808 KB Output is correct
4 Correct 16 ms 23808 KB Output is correct
5 Correct 16 ms 23808 KB Output is correct
6 Correct 16 ms 23808 KB Output is correct
7 Correct 16 ms 23808 KB Output is correct
8 Correct 16 ms 23808 KB Output is correct
9 Correct 16 ms 23808 KB Output is correct
10 Correct 16 ms 23808 KB Output is correct
11 Correct 16 ms 23808 KB Output is correct
12 Correct 16 ms 23808 KB Output is correct
13 Correct 16 ms 23808 KB Output is correct
14 Correct 16 ms 23808 KB Output is correct
15 Correct 16 ms 23808 KB Output is correct
16 Correct 17 ms 23808 KB Output is correct
17 Correct 16 ms 23808 KB Output is correct
18 Correct 16 ms 23808 KB Output is correct
19 Correct 16 ms 23848 KB Output is correct
20 Correct 16 ms 23808 KB Output is correct
21 Correct 17 ms 23936 KB Output is correct
22 Correct 17 ms 23936 KB Output is correct
23 Correct 17 ms 24064 KB Output is correct
24 Correct 19 ms 23936 KB Output is correct
25 Correct 17 ms 23936 KB Output is correct
26 Correct 18 ms 23936 KB Output is correct
27 Correct 17 ms 23936 KB Output is correct
28 Correct 17 ms 23936 KB Output is correct
29 Correct 17 ms 23936 KB Output is correct
30 Correct 17 ms 23936 KB Output is correct
31 Correct 17 ms 23936 KB Output is correct
32 Correct 17 ms 23936 KB Output is correct
33 Correct 18 ms 23936 KB Output is correct
34 Correct 17 ms 23936 KB Output is correct
35 Correct 17 ms 23936 KB Output is correct
36 Correct 17 ms 23936 KB Output is correct
37 Correct 17 ms 23972 KB Output is correct
38 Correct 17 ms 23936 KB Output is correct
39 Correct 17 ms 23936 KB Output is correct
40 Correct 17 ms 23936 KB Output is correct
41 Correct 18 ms 23936 KB Output is correct
42 Correct 17 ms 23936 KB Output is correct
43 Correct 17 ms 23936 KB Output is correct
44 Correct 18 ms 23936 KB Output is correct
45 Correct 17 ms 23936 KB Output is correct
46 Correct 17 ms 23936 KB Output is correct
47 Correct 17 ms 23936 KB Output is correct
48 Correct 17 ms 23936 KB Output is correct
49 Correct 17 ms 23936 KB Output is correct
50 Correct 17 ms 23936 KB Output is correct
51 Correct 17 ms 23936 KB Output is correct
52 Correct 17 ms 23936 KB Output is correct
53 Correct 17 ms 23936 KB Output is correct
54 Correct 17 ms 23936 KB Output is correct
55 Correct 17 ms 23936 KB Output is correct
56 Correct 17 ms 23936 KB Output is correct
57 Correct 18 ms 24192 KB Output is correct
58 Correct 17 ms 23936 KB Output is correct
59 Correct 17 ms 23936 KB Output is correct
60 Correct 17 ms 23936 KB Output is correct
61 Correct 17 ms 23936 KB Output is correct
62 Correct 17 ms 23936 KB Output is correct
63 Correct 17 ms 23936 KB Output is correct
64 Correct 183 ms 34680 KB Output is correct
65 Correct 190 ms 34616 KB Output is correct
66 Correct 186 ms 34600 KB Output is correct
67 Correct 181 ms 34612 KB Output is correct
68 Correct 181 ms 34728 KB Output is correct
69 Correct 180 ms 34612 KB Output is correct
70 Correct 206 ms 34556 KB Output is correct
71 Correct 227 ms 34648 KB Output is correct
72 Correct 196 ms 34612 KB Output is correct
73 Correct 232 ms 41272 KB Output is correct
74 Correct 212 ms 41144 KB Output is correct
75 Correct 202 ms 35892 KB Output is correct
76 Correct 205 ms 35900 KB Output is correct
77 Correct 211 ms 34632 KB Output is correct
78 Correct 217 ms 34620 KB Output is correct
79 Correct 194 ms 34620 KB Output is correct
80 Correct 211 ms 34612 KB Output is correct
81 Correct 165 ms 34768 KB Output is correct
82 Correct 188 ms 34672 KB Output is correct
83 Correct 217 ms 37608 KB Output is correct
84 Correct 220 ms 38932 KB Output is correct
85 Correct 234 ms 38816 KB Output is correct
86 Correct 217 ms 35380 KB Output is correct
87 Correct 213 ms 35212 KB Output is correct
88 Correct 197 ms 35236 KB Output is correct
89 Correct 202 ms 35308 KB Output is correct
90 Correct 206 ms 35096 KB Output is correct
91 Correct 188 ms 35228 KB Output is correct
92 Correct 196 ms 35496 KB Output is correct
93 Correct 190 ms 36720 KB Output is correct
94 Correct 176 ms 37724 KB Output is correct
95 Correct 175 ms 36956 KB Output is correct
96 Correct 187 ms 35768 KB Output is correct
97 Correct 187 ms 34972 KB Output is correct
98 Correct 185 ms 34792 KB Output is correct
99 Correct 200 ms 34740 KB Output is correct
100 Correct 179 ms 36416 KB Output is correct
101 Correct 196 ms 35060 KB Output is correct
102 Correct 178 ms 34824 KB Output is correct
103 Correct 197 ms 34904 KB Output is correct
104 Correct 121 ms 35188 KB Output is correct
105 Correct 203 ms 39352 KB Output is correct
106 Correct 119 ms 35300 KB Output is correct
107 Correct 116 ms 35300 KB Output is correct
108 Correct 198 ms 41652 KB Output is correct
109 Correct 117 ms 35268 KB Output is correct
110 Correct 218 ms 41932 KB Output is correct
111 Correct 187 ms 34568 KB Output is correct