답안 #378403

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378403 2021-03-16T17:11:48 Z qwerty234 Power Plant (JOI20_power) C++14
100 / 100
353 ms 32876 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back

using namespace std;

const int MAXN = 2e5 + 10, inf = 2e9;

int n, m, d[MAXN], dp[MAXN], a[MAXN];
vector <int> g[MAXN];

void dfs(int u, int p) {
  int smd = 0, mxdp = 0, mxd = 0;
  for (int to : g[u]) {
    if (to == p)
      continue;
    dfs(to, u);
    smd += d[to];
    mxdp = max(mxdp, dp[to]);
    mxd = max(mxd, d[to]);
  }
  d[u] = dp[u] = 0;
  d[u] = max(d[u], max(0, smd - a[u]));
  dp[u] = max(dp[u], max(mxdp, smd - a[u]));
  if (a[u] == 1) {
    d[u] = max(d[u], 1);
    dp[u] = max(dp[u], 1 + mxd);
  }
}

main() {
//  freopen("input.txt", "r", stdin);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].pb(v);
    g[v].pb(u);
  }
  for (int i = 1; i <= n; i++) {
    char ch;
    cin >> ch;
    a[i] = ch - '0';
  }
  dfs(1, -1);
  cout << dp[1];
}

Compilation message

power.cpp:33:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   33 | main() {
      |      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 3 ms 4972 KB Output is correct
3 Correct 3 ms 4972 KB Output is correct
4 Correct 3 ms 4972 KB Output is correct
5 Correct 3 ms 4972 KB Output is correct
6 Correct 3 ms 4972 KB Output is correct
7 Correct 3 ms 4972 KB Output is correct
8 Correct 4 ms 5100 KB Output is correct
9 Correct 3 ms 4972 KB Output is correct
10 Correct 3 ms 4972 KB Output is correct
11 Correct 3 ms 4972 KB Output is correct
12 Correct 3 ms 4972 KB Output is correct
13 Correct 4 ms 4972 KB Output is correct
14 Correct 5 ms 4972 KB Output is correct
15 Correct 3 ms 4972 KB Output is correct
16 Correct 3 ms 4972 KB Output is correct
17 Correct 5 ms 5228 KB Output is correct
18 Correct 4 ms 4992 KB Output is correct
19 Correct 3 ms 4972 KB Output is correct
20 Correct 3 ms 4972 KB Output is correct
21 Correct 4 ms 4972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 3 ms 4972 KB Output is correct
3 Correct 3 ms 4972 KB Output is correct
4 Correct 3 ms 4972 KB Output is correct
5 Correct 3 ms 4972 KB Output is correct
6 Correct 3 ms 4972 KB Output is correct
7 Correct 3 ms 4972 KB Output is correct
8 Correct 4 ms 5100 KB Output is correct
9 Correct 3 ms 4972 KB Output is correct
10 Correct 3 ms 4972 KB Output is correct
11 Correct 3 ms 4972 KB Output is correct
12 Correct 3 ms 4972 KB Output is correct
13 Correct 4 ms 4972 KB Output is correct
14 Correct 5 ms 4972 KB Output is correct
15 Correct 3 ms 4972 KB Output is correct
16 Correct 3 ms 4972 KB Output is correct
17 Correct 5 ms 5228 KB Output is correct
18 Correct 4 ms 4992 KB Output is correct
19 Correct 3 ms 4972 KB Output is correct
20 Correct 3 ms 4972 KB Output is correct
21 Correct 4 ms 4972 KB Output is correct
22 Correct 5 ms 5100 KB Output is correct
23 Correct 5 ms 5100 KB Output is correct
24 Correct 5 ms 5100 KB Output is correct
25 Correct 5 ms 5100 KB Output is correct
26 Correct 6 ms 5100 KB Output is correct
27 Correct 6 ms 5100 KB Output is correct
28 Correct 5 ms 5228 KB Output is correct
29 Correct 5 ms 5228 KB Output is correct
30 Correct 5 ms 5244 KB Output is correct
31 Correct 5 ms 5100 KB Output is correct
32 Correct 5 ms 5100 KB Output is correct
33 Correct 5 ms 5120 KB Output is correct
34 Correct 5 ms 5100 KB Output is correct
35 Correct 5 ms 5100 KB Output is correct
36 Correct 5 ms 5100 KB Output is correct
37 Correct 6 ms 5100 KB Output is correct
38 Correct 5 ms 5100 KB Output is correct
39 Correct 5 ms 5228 KB Output is correct
40 Correct 5 ms 5228 KB Output is correct
41 Correct 5 ms 5228 KB Output is correct
42 Correct 5 ms 5100 KB Output is correct
43 Correct 5 ms 5100 KB Output is correct
44 Correct 5 ms 5228 KB Output is correct
45 Correct 5 ms 5100 KB Output is correct
46 Correct 5 ms 5100 KB Output is correct
47 Correct 5 ms 5100 KB Output is correct
48 Correct 7 ms 5228 KB Output is correct
49 Correct 5 ms 5228 KB Output is correct
50 Correct 5 ms 5228 KB Output is correct
51 Correct 5 ms 5228 KB Output is correct
52 Correct 5 ms 5100 KB Output is correct
53 Correct 5 ms 5228 KB Output is correct
54 Correct 5 ms 5100 KB Output is correct
55 Correct 5 ms 5100 KB Output is correct
56 Correct 5 ms 5100 KB Output is correct
57 Correct 5 ms 5356 KB Output is correct
58 Correct 5 ms 5100 KB Output is correct
59 Correct 5 ms 5100 KB Output is correct
60 Correct 6 ms 5228 KB Output is correct
61 Correct 5 ms 5100 KB Output is correct
62 Correct 7 ms 5228 KB Output is correct
63 Correct 6 ms 5100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 3 ms 4972 KB Output is correct
3 Correct 3 ms 4972 KB Output is correct
4 Correct 3 ms 4972 KB Output is correct
5 Correct 3 ms 4972 KB Output is correct
6 Correct 3 ms 4972 KB Output is correct
7 Correct 3 ms 4972 KB Output is correct
8 Correct 4 ms 5100 KB Output is correct
9 Correct 3 ms 4972 KB Output is correct
10 Correct 3 ms 4972 KB Output is correct
11 Correct 3 ms 4972 KB Output is correct
12 Correct 3 ms 4972 KB Output is correct
13 Correct 4 ms 4972 KB Output is correct
14 Correct 5 ms 4972 KB Output is correct
15 Correct 3 ms 4972 KB Output is correct
16 Correct 3 ms 4972 KB Output is correct
17 Correct 5 ms 5228 KB Output is correct
18 Correct 4 ms 4992 KB Output is correct
19 Correct 3 ms 4972 KB Output is correct
20 Correct 3 ms 4972 KB Output is correct
21 Correct 4 ms 4972 KB Output is correct
22 Correct 5 ms 5100 KB Output is correct
23 Correct 5 ms 5100 KB Output is correct
24 Correct 5 ms 5100 KB Output is correct
25 Correct 5 ms 5100 KB Output is correct
26 Correct 6 ms 5100 KB Output is correct
27 Correct 6 ms 5100 KB Output is correct
28 Correct 5 ms 5228 KB Output is correct
29 Correct 5 ms 5228 KB Output is correct
30 Correct 5 ms 5244 KB Output is correct
31 Correct 5 ms 5100 KB Output is correct
32 Correct 5 ms 5100 KB Output is correct
33 Correct 5 ms 5120 KB Output is correct
34 Correct 5 ms 5100 KB Output is correct
35 Correct 5 ms 5100 KB Output is correct
36 Correct 5 ms 5100 KB Output is correct
37 Correct 6 ms 5100 KB Output is correct
38 Correct 5 ms 5100 KB Output is correct
39 Correct 5 ms 5228 KB Output is correct
40 Correct 5 ms 5228 KB Output is correct
41 Correct 5 ms 5228 KB Output is correct
42 Correct 5 ms 5100 KB Output is correct
43 Correct 5 ms 5100 KB Output is correct
44 Correct 5 ms 5228 KB Output is correct
45 Correct 5 ms 5100 KB Output is correct
46 Correct 5 ms 5100 KB Output is correct
47 Correct 5 ms 5100 KB Output is correct
48 Correct 7 ms 5228 KB Output is correct
49 Correct 5 ms 5228 KB Output is correct
50 Correct 5 ms 5228 KB Output is correct
51 Correct 5 ms 5228 KB Output is correct
52 Correct 5 ms 5100 KB Output is correct
53 Correct 5 ms 5228 KB Output is correct
54 Correct 5 ms 5100 KB Output is correct
55 Correct 5 ms 5100 KB Output is correct
56 Correct 5 ms 5100 KB Output is correct
57 Correct 5 ms 5356 KB Output is correct
58 Correct 5 ms 5100 KB Output is correct
59 Correct 5 ms 5100 KB Output is correct
60 Correct 6 ms 5228 KB Output is correct
61 Correct 5 ms 5100 KB Output is correct
62 Correct 7 ms 5228 KB Output is correct
63 Correct 6 ms 5100 KB Output is correct
64 Correct 273 ms 16620 KB Output is correct
65 Correct 274 ms 16556 KB Output is correct
66 Correct 255 ms 16492 KB Output is correct
67 Correct 268 ms 16500 KB Output is correct
68 Correct 273 ms 16492 KB Output is correct
69 Correct 267 ms 16620 KB Output is correct
70 Correct 257 ms 16492 KB Output is correct
71 Correct 253 ms 16492 KB Output is correct
72 Correct 290 ms 16528 KB Output is correct
73 Correct 288 ms 31596 KB Output is correct
74 Correct 296 ms 31596 KB Output is correct
75 Correct 248 ms 16396 KB Output is correct
76 Correct 254 ms 16492 KB Output is correct
77 Correct 315 ms 16364 KB Output is correct
78 Correct 252 ms 16364 KB Output is correct
79 Correct 269 ms 16364 KB Output is correct
80 Correct 263 ms 16292 KB Output is correct
81 Correct 257 ms 16868 KB Output is correct
82 Correct 259 ms 16752 KB Output is correct
83 Correct 270 ms 22636 KB Output is correct
84 Correct 294 ms 25220 KB Output is correct
85 Correct 295 ms 24940 KB Output is correct
86 Correct 276 ms 18028 KB Output is correct
87 Correct 281 ms 17388 KB Output is correct
88 Correct 257 ms 18028 KB Output is correct
89 Correct 246 ms 18028 KB Output is correct
90 Correct 245 ms 17644 KB Output is correct
91 Correct 250 ms 18028 KB Output is correct
92 Correct 267 ms 18284 KB Output is correct
93 Correct 254 ms 21352 KB Output is correct
94 Correct 242 ms 23140 KB Output is correct
95 Correct 236 ms 21608 KB Output is correct
96 Correct 258 ms 19564 KB Output is correct
97 Correct 247 ms 17652 KB Output is correct
98 Correct 245 ms 17132 KB Output is correct
99 Correct 263 ms 16748 KB Output is correct
100 Correct 251 ms 20588 KB Output is correct
101 Correct 251 ms 18412 KB Output is correct
102 Correct 235 ms 17388 KB Output is correct
103 Correct 274 ms 17260 KB Output is correct
104 Correct 204 ms 17376 KB Output is correct
105 Correct 268 ms 27756 KB Output is correct
106 Correct 190 ms 17252 KB Output is correct
107 Correct 190 ms 17120 KB Output is correct
108 Correct 287 ms 32620 KB Output is correct
109 Correct 195 ms 17248 KB Output is correct
110 Correct 353 ms 32876 KB Output is correct
111 Correct 254 ms 16364 KB Output is correct