Submission #292623

# Submission time Handle Problem Language Result Execution time Memory
292623 2020-09-07T10:59:46 Z kdh9949 Power Plant (JOI20_power) C++17
100 / 100
262 ms 33464 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;

using vint = vector<int>;
using vll = vector<ll>;
using vld = vector<ld>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define x first
#define y second
#define all(v) v.begin(),v.end()

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;

  vector<vint> e(n + 1);
  for(int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    e[x].push_back(y);
    e[y].push_back(x);
  }

  string s;
  cin >> s;
  vint a(n + 1);
  for(int i = 0; i < n; i++) a[i + 1] = (s[i] == '1');

  vint d(n + 1), tot(n + 1);
  function<int(int, int)> f = [&](int x, int y) {
    for(int i : e[x]) {
      if(i == y) continue;
      int t = f(i, x);
      tot[x] += t;
    }
    return d[x] = max(tot[x] - a[x], a[x]);
  };
  f(1, 0);

  int ans = min(2, int(count(all(a), 1)));
  function<void(int, int)> g = [&](int x, int y) {
    ans = max(ans, d[x]);
    for(int i : e[x]) {
      if(i == y) continue;
      int dx = d[x], di = d[i], tx = tot[x], ti = tot[i];
      tot[x] -= d[i];
      d[x] = max(tot[x] - a[x], a[x]);
      tot[i] += d[x];
      d[i] = max(tot[i] - a[i], a[i]);
      g(i, x);
      d[x] = dx; d[i] = di; tot[x] = tx; tot[i] = ti;
    }
  };
  g(1, 0);

  cout << ans << '\n';
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 416 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 416 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 640 KB Output is correct
25 Correct 1 ms 416 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
29 Correct 1 ms 640 KB Output is correct
30 Correct 1 ms 640 KB Output is correct
31 Correct 1 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 1 ms 512 KB Output is correct
34 Correct 1 ms 512 KB Output is correct
35 Correct 1 ms 512 KB Output is correct
36 Correct 1 ms 640 KB Output is correct
37 Correct 1 ms 512 KB Output is correct
38 Correct 1 ms 512 KB Output is correct
39 Correct 1 ms 512 KB Output is correct
40 Correct 1 ms 512 KB Output is correct
41 Correct 1 ms 512 KB Output is correct
42 Correct 1 ms 512 KB Output is correct
43 Correct 1 ms 512 KB Output is correct
44 Correct 1 ms 512 KB Output is correct
45 Correct 1 ms 512 KB Output is correct
46 Correct 1 ms 512 KB Output is correct
47 Correct 2 ms 512 KB Output is correct
48 Correct 1 ms 512 KB Output is correct
49 Correct 1 ms 512 KB Output is correct
50 Correct 1 ms 512 KB Output is correct
51 Correct 1 ms 512 KB Output is correct
52 Correct 1 ms 512 KB Output is correct
53 Correct 1 ms 512 KB Output is correct
54 Correct 1 ms 512 KB Output is correct
55 Correct 1 ms 640 KB Output is correct
56 Correct 1 ms 512 KB Output is correct
57 Correct 1 ms 640 KB Output is correct
58 Correct 1 ms 512 KB Output is correct
59 Correct 2 ms 512 KB Output is correct
60 Correct 1 ms 512 KB Output is correct
61 Correct 1 ms 512 KB Output is correct
62 Correct 1 ms 640 KB Output is correct
63 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 416 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 640 KB Output is correct
25 Correct 1 ms 416 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
29 Correct 1 ms 640 KB Output is correct
30 Correct 1 ms 640 KB Output is correct
31 Correct 1 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 1 ms 512 KB Output is correct
34 Correct 1 ms 512 KB Output is correct
35 Correct 1 ms 512 KB Output is correct
36 Correct 1 ms 640 KB Output is correct
37 Correct 1 ms 512 KB Output is correct
38 Correct 1 ms 512 KB Output is correct
39 Correct 1 ms 512 KB Output is correct
40 Correct 1 ms 512 KB Output is correct
41 Correct 1 ms 512 KB Output is correct
42 Correct 1 ms 512 KB Output is correct
43 Correct 1 ms 512 KB Output is correct
44 Correct 1 ms 512 KB Output is correct
45 Correct 1 ms 512 KB Output is correct
46 Correct 1 ms 512 KB Output is correct
47 Correct 2 ms 512 KB Output is correct
48 Correct 1 ms 512 KB Output is correct
49 Correct 1 ms 512 KB Output is correct
50 Correct 1 ms 512 KB Output is correct
51 Correct 1 ms 512 KB Output is correct
52 Correct 1 ms 512 KB Output is correct
53 Correct 1 ms 512 KB Output is correct
54 Correct 1 ms 512 KB Output is correct
55 Correct 1 ms 640 KB Output is correct
56 Correct 1 ms 512 KB Output is correct
57 Correct 1 ms 640 KB Output is correct
58 Correct 1 ms 512 KB Output is correct
59 Correct 2 ms 512 KB Output is correct
60 Correct 1 ms 512 KB Output is correct
61 Correct 1 ms 512 KB Output is correct
62 Correct 1 ms 640 KB Output is correct
63 Correct 1 ms 512 KB Output is correct
64 Correct 219 ms 14268 KB Output is correct
65 Correct 228 ms 14136 KB Output is correct
66 Correct 216 ms 14372 KB Output is correct
67 Correct 221 ms 14136 KB Output is correct
68 Correct 220 ms 14244 KB Output is correct
69 Correct 233 ms 14164 KB Output is correct
70 Correct 223 ms 14152 KB Output is correct
71 Correct 223 ms 14144 KB Output is correct
72 Correct 230 ms 14260 KB Output is correct
73 Correct 255 ms 31800 KB Output is correct
74 Correct 262 ms 31800 KB Output is correct
75 Correct 212 ms 14008 KB Output is correct
76 Correct 219 ms 14144 KB Output is correct
77 Correct 228 ms 14008 KB Output is correct
78 Correct 246 ms 14008 KB Output is correct
79 Correct 235 ms 14016 KB Output is correct
80 Correct 221 ms 14008 KB Output is correct
81 Correct 180 ms 14580 KB Output is correct
82 Correct 204 ms 14332 KB Output is correct
83 Correct 229 ms 21308 KB Output is correct
84 Correct 240 ms 24264 KB Output is correct
85 Correct 237 ms 23748 KB Output is correct
86 Correct 228 ms 16056 KB Output is correct
87 Correct 240 ms 15284 KB Output is correct
88 Correct 248 ms 15608 KB Output is correct
89 Correct 219 ms 15560 KB Output is correct
90 Correct 208 ms 15260 KB Output is correct
91 Correct 223 ms 15696 KB Output is correct
92 Correct 222 ms 16076 KB Output is correct
93 Correct 207 ms 19716 KB Output is correct
94 Correct 228 ms 22128 KB Output is correct
95 Correct 203 ms 20212 KB Output is correct
96 Correct 210 ms 17572 KB Output is correct
97 Correct 210 ms 15380 KB Output is correct
98 Correct 213 ms 14760 KB Output is correct
99 Correct 216 ms 14388 KB Output is correct
100 Correct 208 ms 18852 KB Output is correct
101 Correct 207 ms 16052 KB Output is correct
102 Correct 203 ms 14980 KB Output is correct
103 Correct 214 ms 14936 KB Output is correct
104 Correct 125 ms 14828 KB Output is correct
105 Correct 247 ms 27320 KB Output is correct
106 Correct 122 ms 14960 KB Output is correct
107 Correct 126 ms 14956 KB Output is correct
108 Correct 260 ms 32812 KB Output is correct
109 Correct 122 ms 14828 KB Output is correct
110 Correct 243 ms 33464 KB Output is correct
111 Correct 206 ms 14024 KB Output is correct