답안 #636819

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
636819 2022-08-30T09:35:26 Z valerikk Power Plant (JOI20_power) C++17
100 / 100
181 ms 32344 KB
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int MAX_N = 200005;

void umax(int &a, int b) {
	a = max(a, b);
}

int N;
vector<int> adj[MAX_N];
char S[MAX_N];
int D[MAX_N][2];

void DFS(int u, int p = -1) {
	int sum[2] = {0, 0};
	int mx[2] = {0, 0};
	for(int v : adj[u]) {
		if(v != p) {
			DFS(v, u);
			for(int i = 0; i < 2; ++i) {
				sum[i] += D[v][i];
				umax(mx[i], D[v][i]);
			}
		}
	}
	if(S[u] == '1') {
		umax(D[u][0], sum[1] - 1);
		umax(D[u][0], mx[0]);
		umax(D[u][0], mx[1] + 1);
		umax(D[u][0], 1);
		umax(D[u][1], sum[1] - 1);
		umax(D[u][1], 1);
	} else {
		umax(D[u][0], sum[1]);
		umax(D[u][0], mx[0]);
		umax(D[u][1], sum[1]);
	}
}

int main() {
	scanf("%d", &N);
	for(int i = 0; i < N - 1; ++i) {
		int A, B;
		scanf("%d%d", &A, &B);
		adj[A].push_back(B);
		adj[B].push_back(A);
	}
	scanf("%s", S + 1);
	DFS(1);
	printf("%d\n", D[1][0]);
}

Compilation message

power.cpp: In function 'int main()':
power.cpp:45:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
power.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |   scanf("%d%d", &A, &B);
      |   ~~~~~^~~~~~~~~~~~~~~~
power.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |  scanf("%s", S + 1);
      |  ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 3 ms 4988 KB Output is correct
3 Correct 3 ms 5020 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 4 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4996 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 4 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 2 ms 4996 KB Output is correct
15 Correct 4 ms 4996 KB Output is correct
16 Correct 3 ms 4944 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4924 KB Output is correct
19 Correct 3 ms 5076 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 3 ms 4988 KB Output is correct
3 Correct 3 ms 5020 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 4 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4996 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 4 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 2 ms 4996 KB Output is correct
15 Correct 4 ms 4996 KB Output is correct
16 Correct 3 ms 4944 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4924 KB Output is correct
19 Correct 3 ms 5076 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 5008 KB Output is correct
23 Correct 4 ms 5076 KB Output is correct
24 Correct 5 ms 5008 KB Output is correct
25 Correct 4 ms 5076 KB Output is correct
26 Correct 3 ms 5008 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 4 ms 5076 KB Output is correct
29 Correct 4 ms 5132 KB Output is correct
30 Correct 4 ms 5196 KB Output is correct
31 Correct 3 ms 5076 KB Output is correct
32 Correct 5 ms 5076 KB Output is correct
33 Correct 3 ms 5076 KB Output is correct
34 Correct 4 ms 5008 KB Output is correct
35 Correct 3 ms 5008 KB Output is correct
36 Correct 3 ms 5076 KB Output is correct
37 Correct 4 ms 5008 KB Output is correct
38 Correct 4 ms 5076 KB Output is correct
39 Correct 4 ms 5064 KB Output is correct
40 Correct 3 ms 5140 KB Output is correct
41 Correct 4 ms 5076 KB Output is correct
42 Correct 3 ms 5132 KB Output is correct
43 Correct 3 ms 5076 KB Output is correct
44 Correct 3 ms 5068 KB Output is correct
45 Correct 3 ms 5136 KB Output is correct
46 Correct 4 ms 5076 KB Output is correct
47 Correct 3 ms 5076 KB Output is correct
48 Correct 3 ms 5076 KB Output is correct
49 Correct 3 ms 5076 KB Output is correct
50 Correct 3 ms 5076 KB Output is correct
51 Correct 3 ms 5076 KB Output is correct
52 Correct 3 ms 5088 KB Output is correct
53 Correct 3 ms 5076 KB Output is correct
54 Correct 3 ms 5076 KB Output is correct
55 Correct 4 ms 5076 KB Output is correct
56 Correct 3 ms 5004 KB Output is correct
57 Correct 3 ms 5204 KB Output is correct
58 Correct 3 ms 5004 KB Output is correct
59 Correct 4 ms 5076 KB Output is correct
60 Correct 4 ms 5076 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 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 3 ms 4988 KB Output is correct
3 Correct 3 ms 5020 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 4 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4996 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 4 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 2 ms 4996 KB Output is correct
15 Correct 4 ms 4996 KB Output is correct
16 Correct 3 ms 4944 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4924 KB Output is correct
19 Correct 3 ms 5076 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 5008 KB Output is correct
23 Correct 4 ms 5076 KB Output is correct
24 Correct 5 ms 5008 KB Output is correct
25 Correct 4 ms 5076 KB Output is correct
26 Correct 3 ms 5008 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 4 ms 5076 KB Output is correct
29 Correct 4 ms 5132 KB Output is correct
30 Correct 4 ms 5196 KB Output is correct
31 Correct 3 ms 5076 KB Output is correct
32 Correct 5 ms 5076 KB Output is correct
33 Correct 3 ms 5076 KB Output is correct
34 Correct 4 ms 5008 KB Output is correct
35 Correct 3 ms 5008 KB Output is correct
36 Correct 3 ms 5076 KB Output is correct
37 Correct 4 ms 5008 KB Output is correct
38 Correct 4 ms 5076 KB Output is correct
39 Correct 4 ms 5064 KB Output is correct
40 Correct 3 ms 5140 KB Output is correct
41 Correct 4 ms 5076 KB Output is correct
42 Correct 3 ms 5132 KB Output is correct
43 Correct 3 ms 5076 KB Output is correct
44 Correct 3 ms 5068 KB Output is correct
45 Correct 3 ms 5136 KB Output is correct
46 Correct 4 ms 5076 KB Output is correct
47 Correct 3 ms 5076 KB Output is correct
48 Correct 3 ms 5076 KB Output is correct
49 Correct 3 ms 5076 KB Output is correct
50 Correct 3 ms 5076 KB Output is correct
51 Correct 3 ms 5076 KB Output is correct
52 Correct 3 ms 5088 KB Output is correct
53 Correct 3 ms 5076 KB Output is correct
54 Correct 3 ms 5076 KB Output is correct
55 Correct 4 ms 5076 KB Output is correct
56 Correct 3 ms 5004 KB Output is correct
57 Correct 3 ms 5204 KB Output is correct
58 Correct 3 ms 5004 KB Output is correct
59 Correct 4 ms 5076 KB Output is correct
60 Correct 4 ms 5076 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 5076 KB Output is correct
64 Correct 128 ms 15824 KB Output is correct
65 Correct 132 ms 15892 KB Output is correct
66 Correct 142 ms 15784 KB Output is correct
67 Correct 133 ms 15740 KB Output is correct
68 Correct 124 ms 15816 KB Output is correct
69 Correct 132 ms 15856 KB Output is correct
70 Correct 145 ms 15824 KB Output is correct
71 Correct 149 ms 15812 KB Output is correct
72 Correct 120 ms 15800 KB Output is correct
73 Correct 143 ms 31052 KB Output is correct
74 Correct 152 ms 30828 KB Output is correct
75 Correct 125 ms 15708 KB Output is correct
76 Correct 153 ms 15780 KB Output is correct
77 Correct 147 ms 15596 KB Output is correct
78 Correct 129 ms 15684 KB Output is correct
79 Correct 139 ms 15636 KB Output is correct
80 Correct 157 ms 15636 KB Output is correct
81 Correct 112 ms 16196 KB Output is correct
82 Correct 117 ms 15916 KB Output is correct
83 Correct 149 ms 21920 KB Output is correct
84 Correct 176 ms 24524 KB Output is correct
85 Correct 140 ms 24100 KB Output is correct
86 Correct 139 ms 17352 KB Output is correct
87 Correct 155 ms 16800 KB Output is correct
88 Correct 123 ms 17160 KB Output is correct
89 Correct 129 ms 17204 KB Output is correct
90 Correct 142 ms 16932 KB Output is correct
91 Correct 166 ms 17160 KB Output is correct
92 Correct 122 ms 17564 KB Output is correct
93 Correct 120 ms 20420 KB Output is correct
94 Correct 131 ms 22528 KB Output is correct
95 Correct 135 ms 20980 KB Output is correct
96 Correct 117 ms 18764 KB Output is correct
97 Correct 118 ms 16892 KB Output is correct
98 Correct 123 ms 16436 KB Output is correct
99 Correct 127 ms 16120 KB Output is correct
100 Correct 118 ms 19884 KB Output is correct
101 Correct 120 ms 17676 KB Output is correct
102 Correct 122 ms 16648 KB Output is correct
103 Correct 167 ms 16328 KB Output is correct
104 Correct 80 ms 16524 KB Output is correct
105 Correct 149 ms 27120 KB Output is correct
106 Correct 95 ms 16496 KB Output is correct
107 Correct 90 ms 16356 KB Output is correct
108 Correct 181 ms 31884 KB Output is correct
109 Correct 90 ms 16568 KB Output is correct
110 Correct 165 ms 32344 KB Output is correct
111 Correct 118 ms 15692 KB Output is correct