# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
294117 | 2020-09-08T15:37:16 Z | BThero | Power Plant (JOI20_power) | C++17 | 311 ms | 43384 KB |
// chrono::system_clock::now().time_since_epoch().count() #include<bits/stdc++.h> #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define all(x) (x).begin(), (x).end() #define debug(x) cerr << #x << " = " << x << endl; using namespace std; typedef long long ll; typedef pair<int, int> pii; const int MAXN = (int)2e5 + 5; vector<int> adj[MAXN]; char can[MAXN]; int dp[MAXN], dpUp[MAXN]; int n, ans; void dfs(int v, int pr = -1) { int S = 0; for (int to : adj[v]) { if (to != pr) { dfs(to, v); S += dp[to]; } } if (can[v] == '1') { dp[v] = max(1, S - 1); } else { dp[v] = S; } } void dfs2(int v, int pr = -1) { int S = dpUp[v]; vector<int> sons; for (int to : adj[v]) { if (to != pr) { sons.pb(to); S += dp[to]; } } if (can[v] == '1') { ans = max(ans, max(1, S - 1)); } else { ans = max(ans, S); } for (int to : sons) { S -= dp[to]; if (can[v] == '1') { dpUp[to] = max(1, S - 1); } else { dpUp[to] = S; } dfs2(to, v); S += dp[to]; } } void solve() { scanf("%d", &n); for (int i = 1; i < n; ++i) { int u, v; scanf("%d %d", &u, &v); adj[u].pb(v); adj[v].pb(u); } scanf("%s", can + 1); ans = 0; for (int i = 1; i <= n; ++i) { if (can[i] == '1') { ans++; } } ans = min(ans, 2); dfs(1); dfs2(1); printf("%d\n", ans); } int main() { int tt = 1; while (tt--) { solve(); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | 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 | 5024 KB | Output is correct |
5 | Correct | 4 ms | 5024 KB | Output is correct |
6 | Correct | 4 ms | 4992 KB | Output is correct |
7 | Correct | 4 ms | 4992 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 | 4 ms | 4992 KB | Output is correct |
13 | Correct | 4 ms | 4992 KB | Output is correct |
14 | Correct | 5 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 | 3 ms | 4992 KB | Output is correct |
18 | Correct | 4 ms | 4992 KB | Output is correct |
19 | Correct | 4 ms | 4992 KB | Output is correct |
20 | Correct | 4 ms | 4992 KB | Output is correct |
21 | Correct | 4 ms | 4992 KB | Output is correct |
# | Verdict | Execution time | Memory | 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 | 5024 KB | Output is correct |
5 | Correct | 4 ms | 5024 KB | Output is correct |
6 | Correct | 4 ms | 4992 KB | Output is correct |
7 | Correct | 4 ms | 4992 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 | 4 ms | 4992 KB | Output is correct |
13 | Correct | 4 ms | 4992 KB | Output is correct |
14 | Correct | 5 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 | 3 ms | 4992 KB | Output is correct |
18 | Correct | 4 ms | 4992 KB | Output is correct |
19 | Correct | 4 ms | 4992 KB | Output is correct |
20 | Correct | 4 ms | 4992 KB | Output is correct |
21 | Correct | 4 ms | 4992 KB | Output is correct |
22 | Correct | 5 ms | 5120 KB | Output is correct |
23 | Correct | 5 ms | 5248 KB | Output is correct |
24 | Correct | 6 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 | 5 ms | 5120 KB | Output is correct |
28 | Correct | 5 ms | 5120 KB | Output is correct |
29 | Correct | 5 ms | 5376 KB | Output is correct |
30 | Correct | 6 ms | 5248 KB | Output is correct |
31 | Correct | 5 ms | 5152 KB | Output is correct |
32 | Correct | 5 ms | 5120 KB | Output is correct |
33 | Correct | 6 ms | 5148 KB | Output is correct |
34 | Correct | 5 ms | 5120 KB | Output is correct |
35 | Correct | 5 ms | 5120 KB | Output is correct |
36 | Correct | 5 ms | 5120 KB | Output is correct |
37 | Correct | 4 ms | 5120 KB | Output is correct |
38 | Correct | 5 ms | 5120 KB | Output is correct |
39 | Correct | 5 ms | 5344 KB | Output is correct |
40 | Correct | 5 ms | 5248 KB | Output is correct |
41 | Correct | 5 ms | 5248 KB | Output is correct |
42 | Correct | 5 ms | 5120 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 | 5 ms | 5120 KB | Output is correct |
48 | Correct | 5 ms | 5248 KB | Output is correct |
49 | Correct | 5 ms | 5248 KB | Output is correct |
50 | Correct | 5 ms | 5248 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 | 4 ms | 5120 KB | Output is correct |
57 | Correct | 6 ms | 5376 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 | 5376 KB | Output is correct |
63 | Correct | 5 ms | 5120 KB | Output is correct |
# | Verdict | Execution time | Memory | 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 | 5024 KB | Output is correct |
5 | Correct | 4 ms | 5024 KB | Output is correct |
6 | Correct | 4 ms | 4992 KB | Output is correct |
7 | Correct | 4 ms | 4992 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 | 4 ms | 4992 KB | Output is correct |
13 | Correct | 4 ms | 4992 KB | Output is correct |
14 | Correct | 5 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 | 3 ms | 4992 KB | Output is correct |
18 | Correct | 4 ms | 4992 KB | Output is correct |
19 | Correct | 4 ms | 4992 KB | Output is correct |
20 | Correct | 4 ms | 4992 KB | Output is correct |
21 | Correct | 4 ms | 4992 KB | Output is correct |
22 | Correct | 5 ms | 5120 KB | Output is correct |
23 | Correct | 5 ms | 5248 KB | Output is correct |
24 | Correct | 6 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 | 5 ms | 5120 KB | Output is correct |
28 | Correct | 5 ms | 5120 KB | Output is correct |
29 | Correct | 5 ms | 5376 KB | Output is correct |
30 | Correct | 6 ms | 5248 KB | Output is correct |
31 | Correct | 5 ms | 5152 KB | Output is correct |
32 | Correct | 5 ms | 5120 KB | Output is correct |
33 | Correct | 6 ms | 5148 KB | Output is correct |
34 | Correct | 5 ms | 5120 KB | Output is correct |
35 | Correct | 5 ms | 5120 KB | Output is correct |
36 | Correct | 5 ms | 5120 KB | Output is correct |
37 | Correct | 4 ms | 5120 KB | Output is correct |
38 | Correct | 5 ms | 5120 KB | Output is correct |
39 | Correct | 5 ms | 5344 KB | Output is correct |
40 | Correct | 5 ms | 5248 KB | Output is correct |
41 | Correct | 5 ms | 5248 KB | Output is correct |
42 | Correct | 5 ms | 5120 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 | 5 ms | 5120 KB | Output is correct |
48 | Correct | 5 ms | 5248 KB | Output is correct |
49 | Correct | 5 ms | 5248 KB | Output is correct |
50 | Correct | 5 ms | 5248 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 | 4 ms | 5120 KB | Output is correct |
57 | Correct | 6 ms | 5376 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 | 5376 KB | Output is correct |
63 | Correct | 5 ms | 5120 KB | Output is correct |
64 | Correct | 250 ms | 15868 KB | Output is correct |
65 | Correct | 258 ms | 16120 KB | Output is correct |
66 | Correct | 294 ms | 15992 KB | Output is correct |
67 | Correct | 233 ms | 15864 KB | Output is correct |
68 | Correct | 241 ms | 16120 KB | Output is correct |
69 | Correct | 236 ms | 15864 KB | Output is correct |
70 | Correct | 247 ms | 15992 KB | Output is correct |
71 | Correct | 250 ms | 15992 KB | Output is correct |
72 | Correct | 236 ms | 15864 KB | Output is correct |
73 | Correct | 311 ms | 41468 KB | Output is correct |
74 | Correct | 282 ms | 41080 KB | Output is correct |
75 | Correct | 235 ms | 15992 KB | Output is correct |
76 | Correct | 234 ms | 15864 KB | Output is correct |
77 | Correct | 258 ms | 15736 KB | Output is correct |
78 | Correct | 256 ms | 15992 KB | Output is correct |
79 | Correct | 247 ms | 15736 KB | Output is correct |
80 | Correct | 251 ms | 15864 KB | Output is correct |
81 | Correct | 196 ms | 16624 KB | Output is correct |
82 | Correct | 227 ms | 16372 KB | Output is correct |
83 | Correct | 273 ms | 26232 KB | Output is correct |
84 | Correct | 269 ms | 30456 KB | Output is correct |
85 | Correct | 271 ms | 29944 KB | Output is correct |
86 | Correct | 247 ms | 18552 KB | Output is correct |
87 | Correct | 257 ms | 17400 KB | Output is correct |
88 | Correct | 236 ms | 18040 KB | Output is correct |
89 | Correct | 223 ms | 17880 KB | Output is correct |
90 | Correct | 226 ms | 17448 KB | Output is correct |
91 | Correct | 228 ms | 18164 KB | Output is correct |
92 | Correct | 223 ms | 18644 KB | Output is correct |
93 | Correct | 221 ms | 24016 KB | Output is correct |
94 | Correct | 231 ms | 27048 KB | Output is correct |
95 | Correct | 214 ms | 24604 KB | Output is correct |
96 | Correct | 215 ms | 20840 KB | Output is correct |
97 | Correct | 218 ms | 17620 KB | Output is correct |
98 | Correct | 217 ms | 16504 KB | Output is correct |
99 | Correct | 223 ms | 16376 KB | Output is correct |
100 | Correct | 224 ms | 22904 KB | Output is correct |
101 | Correct | 225 ms | 18620 KB | Output is correct |
102 | Correct | 227 ms | 17144 KB | Output is correct |
103 | Correct | 230 ms | 16504 KB | Output is correct |
104 | Correct | 120 ms | 17512 KB | Output is correct |
105 | Correct | 286 ms | 34936 KB | Output is correct |
106 | Correct | 124 ms | 17384 KB | Output is correct |
107 | Correct | 121 ms | 17384 KB | Output is correct |
108 | Correct | 282 ms | 42872 KB | Output is correct |
109 | Correct | 124 ms | 17512 KB | Output is correct |
110 | Correct | 276 ms | 43384 KB | Output is correct |
111 | Correct | 220 ms | 15992 KB | Output is correct |