답안 #1025012

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1025012 2024-07-16T14:16:37 Z yellowtoad Power Plant (JOI20_power) C++17
100 / 100
219 ms 30284 KB
#include <iostream>
#include <vector>
using namespace std;

int n, dp[200010], b[200010], dpp[200010], ans;
vector<int> edge[200010];
char ch;

void dfs(int u, int v) {
	for (int i = 0; i < edge[u].size(); i++) {
		if (edge[u][i] != v) {
			dfs(edge[u][i],u);
			dp[u] += dp[edge[u][i]];
		}
	}
	if (b[u]) dp[u] = max(dp[u]-1,1);
}

void dfs1(int u, int v, int maxx) {
	int sum = 0;
	dpp[u] = dp[u]+maxx;
	for (int i = 0; i < edge[u].size(); i++) if (edge[u][i] != v) sum += dp[edge[u][i]];
	for (int i = 0; i < edge[u].size(); i++) if (edge[u][i] != v) dfs1(edge[u][i],u,(b[u] ? max(maxx+sum-dp[edge[u][i]]-1,1) : maxx+sum-dp[edge[u][i]]));
}

int main() {
	cin >> n;
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		edge[u].push_back(v);
		edge[v].push_back(u);
	}
	for (int i = 1; i <= n; i++) {
		cin >> ch;
		b[i] = ch-'0';
	}
	dfs(1,0);
	dfs1(1,0,0);
	for (int i = 1; i <= n; i++) ans = max(ans,dpp[i]);
	cout << ans << endl;
}

Compilation message

power.cpp: In function 'void dfs(int, int)':
power.cpp:10:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  for (int i = 0; i < edge[u].size(); i++) {
      |                  ~~^~~~~~~~~~~~~~~~
power.cpp: In function 'void dfs1(int, int, int)':
power.cpp:22:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |  for (int i = 0; i < edge[u].size(); i++) if (edge[u][i] != v) sum += dp[edge[u][i]];
      |                  ~~^~~~~~~~~~~~~~~~
power.cpp:23:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  for (int i = 0; i < edge[u].size(); i++) if (edge[u][i] != v) dfs1(edge[u][i],u,(b[u] ? max(maxx+sum-dp[edge[u][i]]-1,1) : maxx+sum-dp[edge[u][i]]));
      |                  ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 5144 KB Output is correct
4 Correct 2 ms 4952 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 5092 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 5048 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4952 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 3 ms 5208 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 3 ms 5016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 5144 KB Output is correct
4 Correct 2 ms 4952 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 5092 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 5048 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4952 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 3 ms 5208 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 3 ms 5016 KB Output is correct
22 Correct 3 ms 5212 KB Output is correct
23 Correct 3 ms 5212 KB Output is correct
24 Correct 3 ms 5212 KB Output is correct
25 Correct 4 ms 5212 KB Output is correct
26 Correct 3 ms 5212 KB Output is correct
27 Correct 3 ms 5212 KB Output is correct
28 Correct 4 ms 5156 KB Output is correct
29 Correct 3 ms 5212 KB Output is correct
30 Correct 3 ms 5156 KB Output is correct
31 Correct 3 ms 5212 KB Output is correct
32 Correct 4 ms 5024 KB Output is correct
33 Correct 4 ms 5212 KB Output is correct
34 Correct 3 ms 5212 KB Output is correct
35 Correct 3 ms 5212 KB Output is correct
36 Correct 3 ms 5212 KB Output is correct
37 Correct 4 ms 5212 KB Output is correct
38 Correct 4 ms 5212 KB Output is correct
39 Correct 3 ms 5212 KB Output is correct
40 Correct 3 ms 5212 KB Output is correct
41 Correct 4 ms 5212 KB Output is correct
42 Correct 4 ms 5212 KB Output is correct
43 Correct 4 ms 5212 KB Output is correct
44 Correct 3 ms 5212 KB Output is correct
45 Correct 3 ms 5212 KB Output is correct
46 Correct 3 ms 5152 KB Output is correct
47 Correct 3 ms 5212 KB Output is correct
48 Correct 3 ms 5212 KB Output is correct
49 Correct 4 ms 5172 KB Output is correct
50 Correct 3 ms 5212 KB Output is correct
51 Correct 3 ms 5212 KB Output is correct
52 Correct 3 ms 5212 KB Output is correct
53 Correct 3 ms 5212 KB Output is correct
54 Correct 3 ms 5212 KB Output is correct
55 Correct 4 ms 5152 KB Output is correct
56 Correct 4 ms 5208 KB Output is correct
57 Correct 3 ms 5212 KB Output is correct
58 Correct 3 ms 5156 KB Output is correct
59 Correct 3 ms 5216 KB Output is correct
60 Correct 3 ms 5212 KB Output is correct
61 Correct 4 ms 5212 KB Output is correct
62 Correct 5 ms 5212 KB Output is correct
63 Correct 3 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 5144 KB Output is correct
4 Correct 2 ms 4952 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 5092 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 5048 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4952 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 3 ms 5208 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 3 ms 5016 KB Output is correct
22 Correct 3 ms 5212 KB Output is correct
23 Correct 3 ms 5212 KB Output is correct
24 Correct 3 ms 5212 KB Output is correct
25 Correct 4 ms 5212 KB Output is correct
26 Correct 3 ms 5212 KB Output is correct
27 Correct 3 ms 5212 KB Output is correct
28 Correct 4 ms 5156 KB Output is correct
29 Correct 3 ms 5212 KB Output is correct
30 Correct 3 ms 5156 KB Output is correct
31 Correct 3 ms 5212 KB Output is correct
32 Correct 4 ms 5024 KB Output is correct
33 Correct 4 ms 5212 KB Output is correct
34 Correct 3 ms 5212 KB Output is correct
35 Correct 3 ms 5212 KB Output is correct
36 Correct 3 ms 5212 KB Output is correct
37 Correct 4 ms 5212 KB Output is correct
38 Correct 4 ms 5212 KB Output is correct
39 Correct 3 ms 5212 KB Output is correct
40 Correct 3 ms 5212 KB Output is correct
41 Correct 4 ms 5212 KB Output is correct
42 Correct 4 ms 5212 KB Output is correct
43 Correct 4 ms 5212 KB Output is correct
44 Correct 3 ms 5212 KB Output is correct
45 Correct 3 ms 5212 KB Output is correct
46 Correct 3 ms 5152 KB Output is correct
47 Correct 3 ms 5212 KB Output is correct
48 Correct 3 ms 5212 KB Output is correct
49 Correct 4 ms 5172 KB Output is correct
50 Correct 3 ms 5212 KB Output is correct
51 Correct 3 ms 5212 KB Output is correct
52 Correct 3 ms 5212 KB Output is correct
53 Correct 3 ms 5212 KB Output is correct
54 Correct 3 ms 5212 KB Output is correct
55 Correct 4 ms 5152 KB Output is correct
56 Correct 4 ms 5208 KB Output is correct
57 Correct 3 ms 5212 KB Output is correct
58 Correct 3 ms 5156 KB Output is correct
59 Correct 3 ms 5216 KB Output is correct
60 Correct 3 ms 5212 KB Output is correct
61 Correct 4 ms 5212 KB Output is correct
62 Correct 5 ms 5212 KB Output is correct
63 Correct 3 ms 5212 KB Output is correct
64 Correct 132 ms 16464 KB Output is correct
65 Correct 134 ms 16468 KB Output is correct
66 Correct 130 ms 16464 KB Output is correct
67 Correct 134 ms 16548 KB Output is correct
68 Correct 127 ms 16320 KB Output is correct
69 Correct 134 ms 16468 KB Output is correct
70 Correct 130 ms 16528 KB Output is correct
71 Correct 124 ms 16464 KB Output is correct
72 Correct 121 ms 16468 KB Output is correct
73 Correct 144 ms 28964 KB Output is correct
74 Correct 138 ms 29064 KB Output is correct
75 Correct 122 ms 16208 KB Output is correct
76 Correct 114 ms 16264 KB Output is correct
77 Correct 136 ms 16412 KB Output is correct
78 Correct 128 ms 16200 KB Output is correct
79 Correct 116 ms 16212 KB Output is correct
80 Correct 136 ms 16324 KB Output is correct
81 Correct 116 ms 16792 KB Output is correct
82 Correct 121 ms 16416 KB Output is correct
83 Correct 119 ms 21588 KB Output is correct
84 Correct 126 ms 23636 KB Output is correct
85 Correct 122 ms 23392 KB Output is correct
86 Correct 122 ms 17672 KB Output is correct
87 Correct 112 ms 17108 KB Output is correct
88 Correct 121 ms 17744 KB Output is correct
89 Correct 127 ms 17748 KB Output is correct
90 Correct 152 ms 17492 KB Output is correct
91 Correct 219 ms 17744 KB Output is correct
92 Correct 117 ms 18120 KB Output is correct
93 Correct 121 ms 20432 KB Output is correct
94 Correct 110 ms 21964 KB Output is correct
95 Correct 121 ms 20744 KB Output is correct
96 Correct 131 ms 18980 KB Output is correct
97 Correct 147 ms 17596 KB Output is correct
98 Correct 114 ms 17000 KB Output is correct
99 Correct 124 ms 16720 KB Output is correct
100 Correct 118 ms 20048 KB Output is correct
101 Correct 136 ms 17976 KB Output is correct
102 Correct 137 ms 17180 KB Output is correct
103 Correct 112 ms 16980 KB Output is correct
104 Correct 90 ms 16580 KB Output is correct
105 Correct 135 ms 25920 KB Output is correct
106 Correct 93 ms 16992 KB Output is correct
107 Correct 109 ms 16948 KB Output is correct
108 Correct 166 ms 29776 KB Output is correct
109 Correct 98 ms 16364 KB Output is correct
110 Correct 161 ms 30284 KB Output is correct
111 Correct 109 ms 16396 KB Output is correct