답안 #514856

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
514856 2022-01-18T15:28:27 Z ACE_ Power Plant (JOI20_power) C++14
100 / 100
284 ms 28860 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int t, dp[maxn], n, ans;
vector<int> V[maxn];
string s;
void dfs(int u,int p) {
	int m = 0, all = 0;
	for(int i = 0; i < V[u].size(); i++) {
		if(V[u][i] == p) continue;
		dfs(V[u][i], u);
		all += dp[V[u][i]];
		m = max(m, dp[V[u][i]]);
	}
	dp[u] = max(m - (s[u] == '1'), 0 + (s[u] == '1'));
	dp[u] = max(dp[u], all  - (s[u] == '1'));
	ans = max(ans, m + (s[u] == '1')); ans = max(ans, dp[u]);
}
main(){
	cin >> n;
	for(int i = 2; i <= n; i++) {
		int u,v;
		cin >> u >> v;
		V[u].push_back(v); V[v].push_back(u);
	}
	cin >> s; s = '#' + s;
	dfs(1, 0);
	cout << max(ans, dp[1]);
}

Compilation message

power.cpp: In function 'void dfs(int, int)':
power.cpp:9:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |  for(int i = 0; i < V[u].size(); i++) {
      |                 ~~^~~~~~~~~~~~~
power.cpp: At global scope:
power.cpp:19:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   19 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 2 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 4 ms 4996 KB Output is correct
7 Correct 3 ms 5000 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 4940 KB Output is correct
13 Correct 4 ms 4996 KB Output is correct
14 Correct 3 ms 4996 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4992 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 4 ms 5000 KB Output is correct
19 Correct 3 ms 4996 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 2 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 4 ms 4996 KB Output is correct
7 Correct 3 ms 5000 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 4940 KB Output is correct
13 Correct 4 ms 4996 KB Output is correct
14 Correct 3 ms 4996 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4992 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 4 ms 5000 KB Output is correct
19 Correct 3 ms 4996 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 5 ms 4984 KB Output is correct
23 Correct 4 ms 5068 KB Output is correct
24 Correct 4 ms 5040 KB Output is correct
25 Correct 5 ms 5060 KB Output is correct
26 Correct 4 ms 5068 KB Output is correct
27 Correct 5 ms 5068 KB Output is correct
28 Correct 4 ms 5068 KB Output is correct
29 Correct 4 ms 5172 KB Output is correct
30 Correct 4 ms 5068 KB Output is correct
31 Correct 4 ms 5068 KB Output is correct
32 Correct 4 ms 5068 KB Output is correct
33 Correct 4 ms 5068 KB Output is correct
34 Correct 4 ms 5068 KB Output is correct
35 Correct 5 ms 5008 KB Output is correct
36 Correct 4 ms 5068 KB Output is correct
37 Correct 5 ms 4996 KB Output is correct
38 Correct 4 ms 5068 KB Output is correct
39 Correct 4 ms 5068 KB Output is correct
40 Correct 5 ms 5068 KB Output is correct
41 Correct 4 ms 5136 KB Output is correct
42 Correct 4 ms 5068 KB Output is correct
43 Correct 4 ms 5032 KB Output is correct
44 Correct 4 ms 5004 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 4988 KB Output is correct
48 Correct 4 ms 5068 KB Output is correct
49 Correct 5 ms 5076 KB Output is correct
50 Correct 4 ms 5068 KB Output is correct
51 Correct 5 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 6 ms 5108 KB Output is correct
55 Correct 4 ms 5004 KB Output is correct
56 Correct 5 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 5004 KB Output is correct
60 Correct 4 ms 5136 KB Output is correct
61 Correct 4 ms 5004 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 2 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 4 ms 4996 KB Output is correct
7 Correct 3 ms 5000 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 4940 KB Output is correct
13 Correct 4 ms 4996 KB Output is correct
14 Correct 3 ms 4996 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4992 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 4 ms 5000 KB Output is correct
19 Correct 3 ms 4996 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 5 ms 4984 KB Output is correct
23 Correct 4 ms 5068 KB Output is correct
24 Correct 4 ms 5040 KB Output is correct
25 Correct 5 ms 5060 KB Output is correct
26 Correct 4 ms 5068 KB Output is correct
27 Correct 5 ms 5068 KB Output is correct
28 Correct 4 ms 5068 KB Output is correct
29 Correct 4 ms 5172 KB Output is correct
30 Correct 4 ms 5068 KB Output is correct
31 Correct 4 ms 5068 KB Output is correct
32 Correct 4 ms 5068 KB Output is correct
33 Correct 4 ms 5068 KB Output is correct
34 Correct 4 ms 5068 KB Output is correct
35 Correct 5 ms 5008 KB Output is correct
36 Correct 4 ms 5068 KB Output is correct
37 Correct 5 ms 4996 KB Output is correct
38 Correct 4 ms 5068 KB Output is correct
39 Correct 4 ms 5068 KB Output is correct
40 Correct 5 ms 5068 KB Output is correct
41 Correct 4 ms 5136 KB Output is correct
42 Correct 4 ms 5068 KB Output is correct
43 Correct 4 ms 5032 KB Output is correct
44 Correct 4 ms 5004 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 4988 KB Output is correct
48 Correct 4 ms 5068 KB Output is correct
49 Correct 5 ms 5076 KB Output is correct
50 Correct 4 ms 5068 KB Output is correct
51 Correct 5 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 6 ms 5108 KB Output is correct
55 Correct 4 ms 5004 KB Output is correct
56 Correct 5 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 5004 KB Output is correct
60 Correct 4 ms 5136 KB Output is correct
61 Correct 4 ms 5004 KB Output is correct
62 Correct 4 ms 5196 KB Output is correct
63 Correct 4 ms 5068 KB Output is correct
64 Correct 212 ms 15256 KB Output is correct
65 Correct 214 ms 15124 KB Output is correct
66 Correct 197 ms 15244 KB Output is correct
67 Correct 228 ms 15244 KB Output is correct
68 Correct 212 ms 15124 KB Output is correct
69 Correct 223 ms 15324 KB Output is correct
70 Correct 227 ms 15068 KB Output is correct
71 Correct 244 ms 15072 KB Output is correct
72 Correct 194 ms 15072 KB Output is correct
73 Correct 236 ms 27892 KB Output is correct
74 Correct 243 ms 27708 KB Output is correct
75 Correct 211 ms 14988 KB Output is correct
76 Correct 215 ms 15036 KB Output is correct
77 Correct 216 ms 14960 KB Output is correct
78 Correct 218 ms 15064 KB Output is correct
79 Correct 261 ms 14976 KB Output is correct
80 Correct 210 ms 15040 KB Output is correct
81 Correct 187 ms 15704 KB Output is correct
82 Correct 200 ms 15168 KB Output is correct
83 Correct 250 ms 20232 KB Output is correct
84 Correct 222 ms 22348 KB Output is correct
85 Correct 231 ms 22064 KB Output is correct
86 Correct 284 ms 16520 KB Output is correct
87 Correct 238 ms 16060 KB Output is correct
88 Correct 248 ms 16380 KB Output is correct
89 Correct 191 ms 16324 KB Output is correct
90 Correct 252 ms 16092 KB Output is correct
91 Correct 206 ms 16412 KB Output is correct
92 Correct 205 ms 16680 KB Output is correct
93 Correct 238 ms 19008 KB Output is correct
94 Correct 204 ms 20876 KB Output is correct
95 Correct 260 ms 19424 KB Output is correct
96 Correct 236 ms 17760 KB Output is correct
97 Correct 204 ms 16168 KB Output is correct
98 Correct 212 ms 15652 KB Output is correct
99 Correct 204 ms 15384 KB Output is correct
100 Correct 214 ms 18780 KB Output is correct
101 Correct 198 ms 16704 KB Output is correct
102 Correct 233 ms 15996 KB Output is correct
103 Correct 214 ms 15668 KB Output is correct
104 Correct 195 ms 16012 KB Output is correct
105 Correct 258 ms 24564 KB Output is correct
106 Correct 155 ms 15756 KB Output is correct
107 Correct 147 ms 15936 KB Output is correct
108 Correct 247 ms 28520 KB Output is correct
109 Correct 170 ms 16052 KB Output is correct
110 Correct 246 ms 28860 KB Output is correct
111 Correct 242 ms 14944 KB Output is correct