Submission #899317

# Submission time Handle Problem Language Result Execution time Memory
899317 2024-01-05T18:31:03 Z Keys Power Plant (JOI20_power) C++14
100 / 100
101 ms 29596 KB
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
#define ar array
#define all(x) x.begin(), x.end()
#define pb push_back
#define endl '\n'
#define f first
#define s second
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ROF(i, a, b) for (int i = a; i >= b; i--)
#define trav(i, a) for (auto& i : a)
template <class T> istream &operator>>(istream& in, vector<T> &v) {trav(i, v) in >> i; return in;}

#ifdef LOCAL
#include "../../lib/debug.h"
#else
#define dbg(...)
#endif

const int N = 2e5 + 5;
vi g[N];
int dp[N]; // no vertical path
string s;
int ans = 0;

void dfs(int u, int p) {
  int sum = 0, mx = 0;
  trav(v, g[u]) if (v != p) {
    dfs(v, u);
    sum += dp[v]; mx = max(mx, dp[v]);
  }
  if (s[u] == '1') {
    ans = max(ans, max(sum - 1, mx + 1));
    dp[u] = sum - 1; 
    if (dp[u] < 1) dp[u] = 1;
  } else {
    ans = max(ans, sum);
    dp[u] = sum;
  }
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n; cin >> n;
  FOR(i, 0, n - 1) {
    int u, v; cin >> u >> v;
    g[u].pb(v); g[v].pb(u);
  }
  cin >> s; s = '$' + s;
  dfs(1, 0);
  cout << ans << endl;
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6552 KB Output is correct
12 Correct 2 ms 6488 KB Output is correct
13 Correct 2 ms 6492 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 2 ms 6396 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 3 ms 6320 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6552 KB Output is correct
12 Correct 2 ms 6488 KB Output is correct
13 Correct 2 ms 6492 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 2 ms 6396 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 3 ms 6320 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 2 ms 6560 KB Output is correct
24 Correct 2 ms 6492 KB Output is correct
25 Correct 2 ms 6492 KB Output is correct
26 Correct 2 ms 6492 KB Output is correct
27 Correct 2 ms 6744 KB Output is correct
28 Correct 2 ms 6560 KB Output is correct
29 Correct 2 ms 6748 KB Output is correct
30 Correct 2 ms 6492 KB Output is correct
31 Correct 2 ms 6492 KB Output is correct
32 Correct 2 ms 6488 KB Output is correct
33 Correct 2 ms 6492 KB Output is correct
34 Correct 2 ms 6492 KB Output is correct
35 Correct 2 ms 6624 KB Output is correct
36 Correct 2 ms 6492 KB Output is correct
37 Correct 2 ms 6492 KB Output is correct
38 Correct 2 ms 6492 KB Output is correct
39 Correct 2 ms 6492 KB Output is correct
40 Correct 2 ms 6492 KB Output is correct
41 Correct 2 ms 6492 KB Output is correct
42 Correct 2 ms 6492 KB Output is correct
43 Correct 2 ms 6596 KB Output is correct
44 Correct 3 ms 6492 KB Output is correct
45 Correct 2 ms 6492 KB Output is correct
46 Correct 2 ms 6492 KB Output is correct
47 Correct 2 ms 6492 KB Output is correct
48 Correct 2 ms 6492 KB Output is correct
49 Correct 2 ms 6492 KB Output is correct
50 Correct 2 ms 6492 KB Output is correct
51 Correct 2 ms 6492 KB Output is correct
52 Correct 2 ms 6492 KB Output is correct
53 Correct 2 ms 6556 KB Output is correct
54 Correct 2 ms 6492 KB Output is correct
55 Correct 2 ms 6688 KB Output is correct
56 Correct 2 ms 6492 KB Output is correct
57 Correct 2 ms 6748 KB Output is correct
58 Correct 2 ms 6492 KB Output is correct
59 Correct 2 ms 6492 KB Output is correct
60 Correct 2 ms 6492 KB Output is correct
61 Correct 2 ms 6492 KB Output is correct
62 Correct 2 ms 6560 KB Output is correct
63 Correct 2 ms 6632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6552 KB Output is correct
12 Correct 2 ms 6488 KB Output is correct
13 Correct 2 ms 6492 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 2 ms 6396 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 3 ms 6320 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 2 ms 6560 KB Output is correct
24 Correct 2 ms 6492 KB Output is correct
25 Correct 2 ms 6492 KB Output is correct
26 Correct 2 ms 6492 KB Output is correct
27 Correct 2 ms 6744 KB Output is correct
28 Correct 2 ms 6560 KB Output is correct
29 Correct 2 ms 6748 KB Output is correct
30 Correct 2 ms 6492 KB Output is correct
31 Correct 2 ms 6492 KB Output is correct
32 Correct 2 ms 6488 KB Output is correct
33 Correct 2 ms 6492 KB Output is correct
34 Correct 2 ms 6492 KB Output is correct
35 Correct 2 ms 6624 KB Output is correct
36 Correct 2 ms 6492 KB Output is correct
37 Correct 2 ms 6492 KB Output is correct
38 Correct 2 ms 6492 KB Output is correct
39 Correct 2 ms 6492 KB Output is correct
40 Correct 2 ms 6492 KB Output is correct
41 Correct 2 ms 6492 KB Output is correct
42 Correct 2 ms 6492 KB Output is correct
43 Correct 2 ms 6596 KB Output is correct
44 Correct 3 ms 6492 KB Output is correct
45 Correct 2 ms 6492 KB Output is correct
46 Correct 2 ms 6492 KB Output is correct
47 Correct 2 ms 6492 KB Output is correct
48 Correct 2 ms 6492 KB Output is correct
49 Correct 2 ms 6492 KB Output is correct
50 Correct 2 ms 6492 KB Output is correct
51 Correct 2 ms 6492 KB Output is correct
52 Correct 2 ms 6492 KB Output is correct
53 Correct 2 ms 6556 KB Output is correct
54 Correct 2 ms 6492 KB Output is correct
55 Correct 2 ms 6688 KB Output is correct
56 Correct 2 ms 6492 KB Output is correct
57 Correct 2 ms 6748 KB Output is correct
58 Correct 2 ms 6492 KB Output is correct
59 Correct 2 ms 6492 KB Output is correct
60 Correct 2 ms 6492 KB Output is correct
61 Correct 2 ms 6492 KB Output is correct
62 Correct 2 ms 6560 KB Output is correct
63 Correct 2 ms 6632 KB Output is correct
64 Correct 82 ms 17184 KB Output is correct
65 Correct 72 ms 16996 KB Output is correct
66 Correct 68 ms 17088 KB Output is correct
67 Correct 78 ms 17036 KB Output is correct
68 Correct 68 ms 17084 KB Output is correct
69 Correct 65 ms 17012 KB Output is correct
70 Correct 64 ms 16968 KB Output is correct
71 Correct 63 ms 17056 KB Output is correct
72 Correct 65 ms 17016 KB Output is correct
73 Correct 84 ms 28608 KB Output is correct
74 Correct 77 ms 28620 KB Output is correct
75 Correct 71 ms 18320 KB Output is correct
76 Correct 67 ms 18324 KB Output is correct
77 Correct 73 ms 17052 KB Output is correct
78 Correct 65 ms 17036 KB Output is correct
79 Correct 66 ms 17048 KB Output is correct
80 Correct 65 ms 17040 KB Output is correct
81 Correct 56 ms 17092 KB Output is correct
82 Correct 60 ms 16888 KB Output is correct
83 Correct 76 ms 21996 KB Output is correct
84 Correct 92 ms 24236 KB Output is correct
85 Correct 80 ms 23768 KB Output is correct
86 Correct 66 ms 18384 KB Output is correct
87 Correct 67 ms 17612 KB Output is correct
88 Correct 69 ms 17916 KB Output is correct
89 Correct 64 ms 17880 KB Output is correct
90 Correct 65 ms 17708 KB Output is correct
91 Correct 64 ms 17832 KB Output is correct
92 Correct 81 ms 18252 KB Output is correct
93 Correct 64 ms 20428 KB Output is correct
94 Correct 71 ms 22132 KB Output is correct
95 Correct 63 ms 20616 KB Output is correct
96 Correct 62 ms 18904 KB Output is correct
97 Correct 61 ms 17452 KB Output is correct
98 Correct 76 ms 17084 KB Output is correct
99 Correct 65 ms 17104 KB Output is correct
100 Correct 66 ms 19896 KB Output is correct
101 Correct 67 ms 17992 KB Output is correct
102 Correct 60 ms 17308 KB Output is correct
103 Correct 66 ms 17192 KB Output is correct
104 Correct 44 ms 17676 KB Output is correct
105 Correct 78 ms 25384 KB Output is correct
106 Correct 45 ms 17464 KB Output is correct
107 Correct 44 ms 17596 KB Output is correct
108 Correct 77 ms 29392 KB Output is correct
109 Correct 48 ms 17728 KB Output is correct
110 Correct 101 ms 29596 KB Output is correct
111 Correct 59 ms 17000 KB Output is correct