# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
294103 | 2020-09-08T15:26:17 Z | BThero | Power Plant (JOI20_power) | C++17 | 310 ms | 768 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)2e3 + 5; vector<int> adj[MAXN]; char can[MAXN]; int dp[MAXN]; int n; void dfs(int v, int pr = -1) { vector<int> sons; for (int to : adj[v]) { if (to != pr) { dfs(to, v); sons.pb(to); } } if (can[v] == '1') { dp[v] = 1; int S = -1; for (int to : sons) { S += dp[to]; } dp[v] = max(dp[v], S); } else { dp[v] = 0; for (int to : sons) { dp[v] += 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); int ans = 0; for (int i = 1; i <= n; ++i) { if (can[i] == '1') { ans++; } } ans = min(ans, 2); for (int root = 1; root <= n; ++root) { dfs(root); ans = max(ans, dp[root]); } printf("%d\n", ans); } int main() { int tt = 1; while (tt--) { solve(); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 1 ms | 416 KB | Output is correct |
9 | Correct | 0 ms | 384 KB | Output is correct |
10 | Correct | 1 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 | 1 ms | 384 KB | Output is correct |
14 | Correct | 0 ms | 384 KB | Output is correct |
15 | Correct | 1 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 | 0 ms | 384 KB | Output is correct |
19 | Correct | 0 ms | 384 KB | Output is correct |
20 | Correct | 0 ms | 384 KB | Output is correct |
21 | Correct | 1 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 1 ms | 416 KB | Output is correct |
9 | Correct | 0 ms | 384 KB | Output is correct |
10 | Correct | 1 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 | 1 ms | 384 KB | Output is correct |
14 | Correct | 0 ms | 384 KB | Output is correct |
15 | Correct | 1 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 | 0 ms | 384 KB | Output is correct |
19 | Correct | 0 ms | 384 KB | Output is correct |
20 | Correct | 0 ms | 384 KB | Output is correct |
21 | Correct | 1 ms | 384 KB | Output is correct |
22 | Correct | 275 ms | 504 KB | Output is correct |
23 | Correct | 289 ms | 504 KB | Output is correct |
24 | Correct | 300 ms | 632 KB | Output is correct |
25 | Correct | 284 ms | 508 KB | Output is correct |
26 | Correct | 280 ms | 500 KB | Output is correct |
27 | Correct | 275 ms | 504 KB | Output is correct |
28 | Correct | 278 ms | 536 KB | Output is correct |
29 | Correct | 249 ms | 640 KB | Output is correct |
30 | Correct | 268 ms | 760 KB | Output is correct |
31 | Correct | 252 ms | 504 KB | Output is correct |
32 | Correct | 262 ms | 504 KB | Output is correct |
33 | Correct | 268 ms | 504 KB | Output is correct |
34 | Correct | 277 ms | 504 KB | Output is correct |
35 | Correct | 260 ms | 504 KB | Output is correct |
36 | Correct | 256 ms | 504 KB | Output is correct |
37 | Correct | 177 ms | 632 KB | Output is correct |
38 | Correct | 242 ms | 504 KB | Output is correct |
39 | Correct | 290 ms | 512 KB | Output is correct |
40 | Correct | 310 ms | 632 KB | Output is correct |
41 | Correct | 282 ms | 512 KB | Output is correct |
42 | Correct | 292 ms | 632 KB | Output is correct |
43 | Correct | 285 ms | 512 KB | Output is correct |
44 | Correct | 201 ms | 512 KB | Output is correct |
45 | Correct | 208 ms | 536 KB | Output is correct |
46 | Correct | 209 ms | 512 KB | Output is correct |
47 | Correct | 210 ms | 528 KB | Output is correct |
48 | Correct | 157 ms | 636 KB | Output is correct |
49 | Correct | 160 ms | 632 KB | Output is correct |
50 | Correct | 174 ms | 568 KB | Output is correct |
51 | Correct | 173 ms | 544 KB | Output is correct |
52 | Correct | 222 ms | 512 KB | Output is correct |
53 | Correct | 189 ms | 512 KB | Output is correct |
54 | Correct | 190 ms | 632 KB | Output is correct |
55 | Correct | 208 ms | 512 KB | Output is correct |
56 | Correct | 49 ms | 512 KB | Output is correct |
57 | Correct | 252 ms | 680 KB | Output is correct |
58 | Correct | 52 ms | 512 KB | Output is correct |
59 | Correct | 50 ms | 512 KB | Output is correct |
60 | Correct | 255 ms | 768 KB | Output is correct |
61 | Correct | 47 ms | 512 KB | Output is correct |
62 | Correct | 244 ms | 640 KB | Output is correct |
63 | Correct | 252 ms | 504 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 1 ms | 416 KB | Output is correct |
9 | Correct | 0 ms | 384 KB | Output is correct |
10 | Correct | 1 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 | 1 ms | 384 KB | Output is correct |
14 | Correct | 0 ms | 384 KB | Output is correct |
15 | Correct | 1 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 | 0 ms | 384 KB | Output is correct |
19 | Correct | 0 ms | 384 KB | Output is correct |
20 | Correct | 0 ms | 384 KB | Output is correct |
21 | Correct | 1 ms | 384 KB | Output is correct |
22 | Correct | 275 ms | 504 KB | Output is correct |
23 | Correct | 289 ms | 504 KB | Output is correct |
24 | Correct | 300 ms | 632 KB | Output is correct |
25 | Correct | 284 ms | 508 KB | Output is correct |
26 | Correct | 280 ms | 500 KB | Output is correct |
27 | Correct | 275 ms | 504 KB | Output is correct |
28 | Correct | 278 ms | 536 KB | Output is correct |
29 | Correct | 249 ms | 640 KB | Output is correct |
30 | Correct | 268 ms | 760 KB | Output is correct |
31 | Correct | 252 ms | 504 KB | Output is correct |
32 | Correct | 262 ms | 504 KB | Output is correct |
33 | Correct | 268 ms | 504 KB | Output is correct |
34 | Correct | 277 ms | 504 KB | Output is correct |
35 | Correct | 260 ms | 504 KB | Output is correct |
36 | Correct | 256 ms | 504 KB | Output is correct |
37 | Correct | 177 ms | 632 KB | Output is correct |
38 | Correct | 242 ms | 504 KB | Output is correct |
39 | Correct | 290 ms | 512 KB | Output is correct |
40 | Correct | 310 ms | 632 KB | Output is correct |
41 | Correct | 282 ms | 512 KB | Output is correct |
42 | Correct | 292 ms | 632 KB | Output is correct |
43 | Correct | 285 ms | 512 KB | Output is correct |
44 | Correct | 201 ms | 512 KB | Output is correct |
45 | Correct | 208 ms | 536 KB | Output is correct |
46 | Correct | 209 ms | 512 KB | Output is correct |
47 | Correct | 210 ms | 528 KB | Output is correct |
48 | Correct | 157 ms | 636 KB | Output is correct |
49 | Correct | 160 ms | 632 KB | Output is correct |
50 | Correct | 174 ms | 568 KB | Output is correct |
51 | Correct | 173 ms | 544 KB | Output is correct |
52 | Correct | 222 ms | 512 KB | Output is correct |
53 | Correct | 189 ms | 512 KB | Output is correct |
54 | Correct | 190 ms | 632 KB | Output is correct |
55 | Correct | 208 ms | 512 KB | Output is correct |
56 | Correct | 49 ms | 512 KB | Output is correct |
57 | Correct | 252 ms | 680 KB | Output is correct |
58 | Correct | 52 ms | 512 KB | Output is correct |
59 | Correct | 50 ms | 512 KB | Output is correct |
60 | Correct | 255 ms | 768 KB | Output is correct |
61 | Correct | 47 ms | 512 KB | Output is correct |
62 | Correct | 244 ms | 640 KB | Output is correct |
63 | Correct | 252 ms | 504 KB | Output is correct |
64 | Runtime error | 1 ms | 512 KB | Execution killed with signal 11 |
65 | Halted | 0 ms | 0 KB | - |