# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
292865 | 2020-09-07T14:24:09 Z | luciocf | Power Plant (JOI20_power) | C++14 | 285 ms | 28664 KB |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5+10; int tem[maxn]; int dp[maxn]; int soma[maxn]; vector<int> grafo[maxn]; void dfs(int u, int p) { if (tem[u] && p) dp[u] = 2; int mx = 0; for (auto v: grafo[u]) { if (v == p) continue; dfs(v, u); mx = max(mx, dp[v]-tem[v]); soma[u] += dp[v]-tem[v]; } if (p == 0) dp[u] = max(dp[u], mx); else dp[u] = max(dp[u], soma[u]); } int ans; void solve(int u, int p) { if (tem[u]) ans = max(ans, dp[u]+1); for (auto v: grafo[u]) { if (v == p) continue; int dp_ant = dp[u], soma_ant = soma[u]; soma[u] -= (dp[v]-tem[v]); if (tem[u]) dp[u] = max(2, soma[u]); else dp[u] = max(0, soma[u]); soma[v] += dp[u]-tem[u]; if (tem[v]) { dp[v] = 0; for (auto w: grafo[v]) dp[v] = max(dp[v], dp[w]-tem[w]); } else dp[v] = max(0, soma[v]); solve(v, u); dp[u] = dp_ant, soma[u] = soma_ant; } } int main(void) { int n; scanf("%d", &n); for (int i = 1; i < n; i++) { int u, v; scanf("%d %d", &u, &v); grafo[u].push_back(v); grafo[v].push_back(u); } for (int i = 1; i <= n; i++) { char c; scanf(" %c", &c); if (c == '1') tem[i] = 1; } int r = 0; for (int i = 1; i <= n; i++) if (tem[i]) r = i; dfs(r, 0); solve(r, 0); printf("%d\n", ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 4992 KB | Output is correct |
2 | Correct | 3 ms | 4992 KB | Output is correct |
3 | Correct | 4 ms | 4992 KB | Output is correct |
4 | Correct | 4 ms | 4992 KB | Output is correct |
5 | Correct | 3 ms | 4992 KB | Output is correct |
6 | Correct | 3 ms | 4992 KB | Output is correct |
7 | Correct | 4 ms | 5120 KB | Output is correct |
8 | Correct | 4 ms | 4992 KB | Output is correct |
9 | Correct | 4 ms | 4992 KB | Output is correct |
10 | Correct | 4 ms | 4992 KB | Output is correct |
11 | Correct | 4 ms | 4992 KB | Output is correct |
12 | Correct | 3 ms | 4992 KB | Output is correct |
13 | Correct | 3 ms | 4992 KB | Output is correct |
14 | Correct | 4 ms | 4992 KB | Output is correct |
15 | Correct | 4 ms | 4992 KB | Output is correct |
16 | Correct | 4 ms | 4992 KB | Output is correct |
17 | Correct | 4 ms | 4992 KB | Output is correct |
18 | Correct | 3 ms | 4992 KB | Output is correct |
19 | Correct | 3 ms | 4992 KB | Output is correct |
20 | Correct | 3 ms | 4992 KB | Output is correct |
21 | Correct | 4 ms | 5120 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 4992 KB | Output is correct |
2 | Correct | 3 ms | 4992 KB | Output is correct |
3 | Correct | 4 ms | 4992 KB | Output is correct |
4 | Correct | 4 ms | 4992 KB | Output is correct |
5 | Correct | 3 ms | 4992 KB | Output is correct |
6 | Correct | 3 ms | 4992 KB | Output is correct |
7 | Correct | 4 ms | 5120 KB | Output is correct |
8 | Correct | 4 ms | 4992 KB | Output is correct |
9 | Correct | 4 ms | 4992 KB | Output is correct |
10 | Correct | 4 ms | 4992 KB | Output is correct |
11 | Correct | 4 ms | 4992 KB | Output is correct |
12 | Correct | 3 ms | 4992 KB | Output is correct |
13 | Correct | 3 ms | 4992 KB | Output is correct |
14 | Correct | 4 ms | 4992 KB | Output is correct |
15 | Correct | 4 ms | 4992 KB | Output is correct |
16 | Correct | 4 ms | 4992 KB | Output is correct |
17 | Correct | 4 ms | 4992 KB | Output is correct |
18 | Correct | 3 ms | 4992 KB | Output is correct |
19 | Correct | 3 ms | 4992 KB | Output is correct |
20 | Correct | 3 ms | 4992 KB | Output is correct |
21 | Correct | 4 ms | 5120 KB | Output is correct |
22 | Correct | 5 ms | 5120 KB | Output is correct |
23 | Correct | 5 ms | 5120 KB | Output is correct |
24 | Correct | 5 ms | 5120 KB | Output is correct |
25 | Correct | 5 ms | 5120 KB | Output is correct |
26 | Correct | 5 ms | 5120 KB | Output is correct |
27 | Correct | 4 ms | 5120 KB | Output is correct |
28 | Correct | 5 ms | 5120 KB | Output is correct |
29 | Correct | 5 ms | 5248 KB | Output is correct |
30 | Correct | 5 ms | 5248 KB | Output is correct |
31 | Correct | 5 ms | 5120 KB | Output is correct |
32 | Correct | 5 ms | 5120 KB | Output is correct |
33 | Correct | 5 ms | 5120 KB | Output is correct |
34 | Correct | 5 ms | 5120 KB | Output is correct |
35 | Correct | 5 ms | 5120 KB | Output is correct |
36 | Correct | 6 ms | 5120 KB | Output is correct |
37 | Correct | 5 ms | 5120 KB | Output is correct |
38 | Correct | 5 ms | 5120 KB | Output is correct |
39 | Correct | 5 ms | 5120 KB | Output is correct |
40 | Correct | 5 ms | 5120 KB | Output is correct |
41 | Correct | 5 ms | 5120 KB | Output is correct |
42 | Correct | 6 ms | 5140 KB | Output is correct |
43 | Correct | 5 ms | 5120 KB | Output is correct |
44 | Correct | 5 ms | 5120 KB | Output is correct |
45 | Correct | 5 ms | 5120 KB | Output is correct |
46 | Correct | 5 ms | 5120 KB | Output is correct |
47 | Correct | 6 ms | 5120 KB | Output is correct |
48 | Correct | 4 ms | 5120 KB | Output is correct |
49 | Correct | 5 ms | 5120 KB | Output is correct |
50 | Correct | 4 ms | 5120 KB | Output is correct |
51 | Correct | 5 ms | 5120 KB | Output is correct |
52 | Correct | 5 ms | 5120 KB | Output is correct |
53 | Correct | 5 ms | 5120 KB | Output is correct |
54 | Correct | 5 ms | 5120 KB | Output is correct |
55 | Correct | 5 ms | 5120 KB | Output is correct |
56 | Correct | 5 ms | 5120 KB | Output is correct |
57 | Correct | 5 ms | 5248 KB | Output is correct |
58 | Correct | 4 ms | 5120 KB | Output is correct |
59 | Correct | 5 ms | 5120 KB | Output is correct |
60 | Correct | 5 ms | 5248 KB | Output is correct |
61 | Correct | 4 ms | 5120 KB | Output is correct |
62 | Correct | 5 ms | 5248 KB | Output is correct |
63 | Correct | 4 ms | 5120 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 4992 KB | Output is correct |
2 | Correct | 3 ms | 4992 KB | Output is correct |
3 | Correct | 4 ms | 4992 KB | Output is correct |
4 | Correct | 4 ms | 4992 KB | Output is correct |
5 | Correct | 3 ms | 4992 KB | Output is correct |
6 | Correct | 3 ms | 4992 KB | Output is correct |
7 | Correct | 4 ms | 5120 KB | Output is correct |
8 | Correct | 4 ms | 4992 KB | Output is correct |
9 | Correct | 4 ms | 4992 KB | Output is correct |
10 | Correct | 4 ms | 4992 KB | Output is correct |
11 | Correct | 4 ms | 4992 KB | Output is correct |
12 | Correct | 3 ms | 4992 KB | Output is correct |
13 | Correct | 3 ms | 4992 KB | Output is correct |
14 | Correct | 4 ms | 4992 KB | Output is correct |
15 | Correct | 4 ms | 4992 KB | Output is correct |
16 | Correct | 4 ms | 4992 KB | Output is correct |
17 | Correct | 4 ms | 4992 KB | Output is correct |
18 | Correct | 3 ms | 4992 KB | Output is correct |
19 | Correct | 3 ms | 4992 KB | Output is correct |
20 | Correct | 3 ms | 4992 KB | Output is correct |
21 | Correct | 4 ms | 5120 KB | Output is correct |
22 | Correct | 5 ms | 5120 KB | Output is correct |
23 | Correct | 5 ms | 5120 KB | Output is correct |
24 | Correct | 5 ms | 5120 KB | Output is correct |
25 | Correct | 5 ms | 5120 KB | Output is correct |
26 | Correct | 5 ms | 5120 KB | Output is correct |
27 | Correct | 4 ms | 5120 KB | Output is correct |
28 | Correct | 5 ms | 5120 KB | Output is correct |
29 | Correct | 5 ms | 5248 KB | Output is correct |
30 | Correct | 5 ms | 5248 KB | Output is correct |
31 | Correct | 5 ms | 5120 KB | Output is correct |
32 | Correct | 5 ms | 5120 KB | Output is correct |
33 | Correct | 5 ms | 5120 KB | Output is correct |
34 | Correct | 5 ms | 5120 KB | Output is correct |
35 | Correct | 5 ms | 5120 KB | Output is correct |
36 | Correct | 6 ms | 5120 KB | Output is correct |
37 | Correct | 5 ms | 5120 KB | Output is correct |
38 | Correct | 5 ms | 5120 KB | Output is correct |
39 | Correct | 5 ms | 5120 KB | Output is correct |
40 | Correct | 5 ms | 5120 KB | Output is correct |
41 | Correct | 5 ms | 5120 KB | Output is correct |
42 | Correct | 6 ms | 5140 KB | Output is correct |
43 | Correct | 5 ms | 5120 KB | Output is correct |
44 | Correct | 5 ms | 5120 KB | Output is correct |
45 | Correct | 5 ms | 5120 KB | Output is correct |
46 | Correct | 5 ms | 5120 KB | Output is correct |
47 | Correct | 6 ms | 5120 KB | Output is correct |
48 | Correct | 4 ms | 5120 KB | Output is correct |
49 | Correct | 5 ms | 5120 KB | Output is correct |
50 | Correct | 4 ms | 5120 KB | Output is correct |
51 | Correct | 5 ms | 5120 KB | Output is correct |
52 | Correct | 5 ms | 5120 KB | Output is correct |
53 | Correct | 5 ms | 5120 KB | Output is correct |
54 | Correct | 5 ms | 5120 KB | Output is correct |
55 | Correct | 5 ms | 5120 KB | Output is correct |
56 | Correct | 5 ms | 5120 KB | Output is correct |
57 | Correct | 5 ms | 5248 KB | Output is correct |
58 | Correct | 4 ms | 5120 KB | Output is correct |
59 | Correct | 5 ms | 5120 KB | Output is correct |
60 | Correct | 5 ms | 5248 KB | Output is correct |
61 | Correct | 4 ms | 5120 KB | Output is correct |
62 | Correct | 5 ms | 5248 KB | Output is correct |
63 | Correct | 4 ms | 5120 KB | Output is correct |
64 | Correct | 247 ms | 13676 KB | Output is correct |
65 | Correct | 249 ms | 13688 KB | Output is correct |
66 | Correct | 249 ms | 13816 KB | Output is correct |
67 | Correct | 237 ms | 13688 KB | Output is correct |
68 | Correct | 263 ms | 13688 KB | Output is correct |
69 | Correct | 261 ms | 13692 KB | Output is correct |
70 | Correct | 241 ms | 13688 KB | Output is correct |
71 | Correct | 248 ms | 13816 KB | Output is correct |
72 | Correct | 241 ms | 12920 KB | Output is correct |
73 | Correct | 280 ms | 27640 KB | Output is correct |
74 | Correct | 273 ms | 25080 KB | Output is correct |
75 | Correct | 233 ms | 13560 KB | Output is correct |
76 | Correct | 251 ms | 13560 KB | Output is correct |
77 | Correct | 245 ms | 13560 KB | Output is correct |
78 | Correct | 263 ms | 13560 KB | Output is correct |
79 | Correct | 243 ms | 13808 KB | Output is correct |
80 | Correct | 247 ms | 13560 KB | Output is correct |
81 | Correct | 199 ms | 14060 KB | Output is correct |
82 | Correct | 233 ms | 13940 KB | Output is correct |
83 | Correct | 268 ms | 18680 KB | Output is correct |
84 | Correct | 266 ms | 18936 KB | Output is correct |
85 | Correct | 263 ms | 20600 KB | Output is correct |
86 | Correct | 241 ms | 14684 KB | Output is correct |
87 | Correct | 244 ms | 15224 KB | Output is correct |
88 | Correct | 237 ms | 14748 KB | Output is correct |
89 | Correct | 236 ms | 15200 KB | Output is correct |
90 | Correct | 237 ms | 14832 KB | Output is correct |
91 | Correct | 233 ms | 15096 KB | Output is correct |
92 | Correct | 232 ms | 15352 KB | Output is correct |
93 | Correct | 231 ms | 20212 KB | Output is correct |
94 | Correct | 211 ms | 17956 KB | Output is correct |
95 | Correct | 225 ms | 19956 KB | Output is correct |
96 | Correct | 246 ms | 17528 KB | Output is correct |
97 | Correct | 221 ms | 14904 KB | Output is correct |
98 | Correct | 237 ms | 14584 KB | Output is correct |
99 | Correct | 240 ms | 14072 KB | Output is correct |
100 | Correct | 226 ms | 17272 KB | Output is correct |
101 | Correct | 240 ms | 15480 KB | Output is correct |
102 | Correct | 228 ms | 14584 KB | Output is correct |
103 | Correct | 240 ms | 14328 KB | Output is correct |
104 | Correct | 135 ms | 13808 KB | Output is correct |
105 | Correct | 273 ms | 28576 KB | Output is correct |
106 | Correct | 136 ms | 14440 KB | Output is correct |
107 | Correct | 140 ms | 14568 KB | Output is correct |
108 | Correct | 265 ms | 28536 KB | Output is correct |
109 | Correct | 130 ms | 13672 KB | Output is correct |
110 | Correct | 285 ms | 28664 KB | Output is correct |
111 | Correct | 217 ms | 13560 KB | Output is correct |