# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
529590 | 2022-02-23T08:44:32 Z | MilosMilutinovic | Power Plant (JOI20_power) | C++14 | 183 ms | 28812 KB |
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (int)(n); i ++) #define rep1(i, n) for(int i = 1; i <= (int)(n); i ++) #define MP make_pair using namespace std; typedef long long LL; typedef pair<int, int> PII; int n, dp[200005], ans; vector<int> G[200005]; char s[200005]; void dfs(int v, int par) { rep(i, G[v].size()) { int u = G[v][i]; if(u == par) continue; dfs(u, v); if(s[v] == '1') ans = max(ans, dp[u] + 1); dp[v] += dp[u]; } dp[v] -= (s[v] == '1' ? 1 : 0); if(s[v] == '1') dp[v] = max(dp[v], 1); ans = max(ans, dp[v]); } int main() { scanf("%d", &n); rep(i, n - 1) { int a, b; scanf("%d%d", &a, &b); G[a].push_back(b); G[b].push_back(a); } scanf("%s", s + 1); dfs(1, 0); printf("%d", ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4940 KB | Output is correct |
2 | Correct | 3 ms | 4940 KB | Output is correct |
3 | Correct | 3 ms | 4940 KB | Output is correct |
4 | Correct | 4 ms | 4944 KB | Output is correct |
5 | Correct | 3 ms | 4940 KB | Output is correct |
6 | Correct | 3 ms | 4940 KB | Output is correct |
7 | Correct | 3 ms | 4940 KB | Output is correct |
8 | Correct | 3 ms | 5000 KB | Output is correct |
9 | Correct | 3 ms | 4940 KB | Output is correct |
10 | Correct | 3 ms | 4940 KB | Output is correct |
11 | Correct | 3 ms | 4940 KB | Output is correct |
12 | Correct | 3 ms | 4940 KB | Output is correct |
13 | Correct | 3 ms | 4940 KB | Output is correct |
14 | Correct | 3 ms | 4996 KB | Output is correct |
15 | Correct | 3 ms | 5000 KB | Output is correct |
16 | Correct | 2 ms | 4940 KB | Output is correct |
17 | Correct | 3 ms | 5000 KB | Output is correct |
18 | Correct | 3 ms | 4996 KB | Output is correct |
19 | Correct | 3 ms | 4940 KB | Output is correct |
20 | Correct | 3 ms | 4884 KB | Output is correct |
21 | Correct | 3 ms | 4940 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4940 KB | Output is correct |
2 | Correct | 3 ms | 4940 KB | Output is correct |
3 | Correct | 3 ms | 4940 KB | Output is correct |
4 | Correct | 4 ms | 4944 KB | Output is correct |
5 | Correct | 3 ms | 4940 KB | Output is correct |
6 | Correct | 3 ms | 4940 KB | Output is correct |
7 | Correct | 3 ms | 4940 KB | Output is correct |
8 | Correct | 3 ms | 5000 KB | Output is correct |
9 | Correct | 3 ms | 4940 KB | Output is correct |
10 | Correct | 3 ms | 4940 KB | Output is correct |
11 | Correct | 3 ms | 4940 KB | Output is correct |
12 | Correct | 3 ms | 4940 KB | Output is correct |
13 | Correct | 3 ms | 4940 KB | Output is correct |
14 | Correct | 3 ms | 4996 KB | Output is correct |
15 | Correct | 3 ms | 5000 KB | Output is correct |
16 | Correct | 2 ms | 4940 KB | Output is correct |
17 | Correct | 3 ms | 5000 KB | Output is correct |
18 | Correct | 3 ms | 4996 KB | Output is correct |
19 | Correct | 3 ms | 4940 KB | Output is correct |
20 | Correct | 3 ms | 4884 KB | Output is correct |
21 | Correct | 3 ms | 4940 KB | Output is correct |
22 | Correct | 3 ms | 5068 KB | Output is correct |
23 | Correct | 4 ms | 5068 KB | Output is correct |
24 | Correct | 3 ms | 5068 KB | Output is correct |
25 | Correct | 4 ms | 5068 KB | Output is correct |
26 | Correct | 4 ms | 5016 KB | Output is correct |
27 | Correct | 4 ms | 5068 KB | Output is correct |
28 | Correct | 4 ms | 5012 KB | Output is correct |
29 | Correct | 4 ms | 5136 KB | Output is correct |
30 | Correct | 4 ms | 5084 KB | Output is correct |
31 | Correct | 4 ms | 5068 KB | Output is correct |
32 | Correct | 3 ms | 5068 KB | Output is correct |
33 | Correct | 4 ms | 5068 KB | Output is correct |
34 | Correct | 4 ms | 5068 KB | Output is correct |
35 | Correct | 3 ms | 5064 KB | Output is correct |
36 | Correct | 3 ms | 5068 KB | Output is correct |
37 | Correct | 4 ms | 5068 KB | Output is correct |
38 | Correct | 3 ms | 5048 KB | Output is correct |
39 | Correct | 4 ms | 5140 KB | Output is correct |
40 | Correct | 3 ms | 5068 KB | Output is correct |
41 | Correct | 4 ms | 5136 KB | Output is correct |
42 | Correct | 4 ms | 5068 KB | Output is correct |
43 | Correct | 3 ms | 5012 KB | Output is correct |
44 | Correct | 3 ms | 5008 KB | Output is correct |
45 | Correct | 4 ms | 5068 KB | Output is correct |
46 | Correct | 4 ms | 5012 KB | Output is correct |
47 | Correct | 3 ms | 5068 KB | Output is correct |
48 | Correct | 4 ms | 5068 KB | Output is correct |
49 | Correct | 4 ms | 5068 KB | Output is correct |
50 | Correct | 4 ms | 5068 KB | Output is correct |
51 | Correct | 3 ms | 5068 KB | Output is correct |
52 | Correct | 3 ms | 5016 KB | Output is correct |
53 | Correct | 4 ms | 5068 KB | Output is correct |
54 | Correct | 3 ms | 5068 KB | Output is correct |
55 | Correct | 4 ms | 5068 KB | Output is correct |
56 | Correct | 3 ms | 5068 KB | Output is correct |
57 | Correct | 4 ms | 5196 KB | Output is correct |
58 | Correct | 3 ms | 5016 KB | Output is correct |
59 | Correct | 4 ms | 5008 KB | Output is correct |
60 | Correct | 4 ms | 5068 KB | Output is correct |
61 | Correct | 4 ms | 5068 KB | Output is correct |
62 | Correct | 4 ms | 5140 KB | Output is correct |
63 | Correct | 3 ms | 5012 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4940 KB | Output is correct |
2 | Correct | 3 ms | 4940 KB | Output is correct |
3 | Correct | 3 ms | 4940 KB | Output is correct |
4 | Correct | 4 ms | 4944 KB | Output is correct |
5 | Correct | 3 ms | 4940 KB | Output is correct |
6 | Correct | 3 ms | 4940 KB | Output is correct |
7 | Correct | 3 ms | 4940 KB | Output is correct |
8 | Correct | 3 ms | 5000 KB | Output is correct |
9 | Correct | 3 ms | 4940 KB | Output is correct |
10 | Correct | 3 ms | 4940 KB | Output is correct |
11 | Correct | 3 ms | 4940 KB | Output is correct |
12 | Correct | 3 ms | 4940 KB | Output is correct |
13 | Correct | 3 ms | 4940 KB | Output is correct |
14 | Correct | 3 ms | 4996 KB | Output is correct |
15 | Correct | 3 ms | 5000 KB | Output is correct |
16 | Correct | 2 ms | 4940 KB | Output is correct |
17 | Correct | 3 ms | 5000 KB | Output is correct |
18 | Correct | 3 ms | 4996 KB | Output is correct |
19 | Correct | 3 ms | 4940 KB | Output is correct |
20 | Correct | 3 ms | 4884 KB | Output is correct |
21 | Correct | 3 ms | 4940 KB | Output is correct |
22 | Correct | 3 ms | 5068 KB | Output is correct |
23 | Correct | 4 ms | 5068 KB | Output is correct |
24 | Correct | 3 ms | 5068 KB | Output is correct |
25 | Correct | 4 ms | 5068 KB | Output is correct |
26 | Correct | 4 ms | 5016 KB | Output is correct |
27 | Correct | 4 ms | 5068 KB | Output is correct |
28 | Correct | 4 ms | 5012 KB | Output is correct |
29 | Correct | 4 ms | 5136 KB | Output is correct |
30 | Correct | 4 ms | 5084 KB | Output is correct |
31 | Correct | 4 ms | 5068 KB | Output is correct |
32 | Correct | 3 ms | 5068 KB | Output is correct |
33 | Correct | 4 ms | 5068 KB | Output is correct |
34 | Correct | 4 ms | 5068 KB | Output is correct |
35 | Correct | 3 ms | 5064 KB | Output is correct |
36 | Correct | 3 ms | 5068 KB | Output is correct |
37 | Correct | 4 ms | 5068 KB | Output is correct |
38 | Correct | 3 ms | 5048 KB | Output is correct |
39 | Correct | 4 ms | 5140 KB | Output is correct |
40 | Correct | 3 ms | 5068 KB | Output is correct |
41 | Correct | 4 ms | 5136 KB | Output is correct |
42 | Correct | 4 ms | 5068 KB | Output is correct |
43 | Correct | 3 ms | 5012 KB | Output is correct |
44 | Correct | 3 ms | 5008 KB | Output is correct |
45 | Correct | 4 ms | 5068 KB | Output is correct |
46 | Correct | 4 ms | 5012 KB | Output is correct |
47 | Correct | 3 ms | 5068 KB | Output is correct |
48 | Correct | 4 ms | 5068 KB | Output is correct |
49 | Correct | 4 ms | 5068 KB | Output is correct |
50 | Correct | 4 ms | 5068 KB | Output is correct |
51 | Correct | 3 ms | 5068 KB | Output is correct |
52 | Correct | 3 ms | 5016 KB | Output is correct |
53 | Correct | 4 ms | 5068 KB | Output is correct |
54 | Correct | 3 ms | 5068 KB | Output is correct |
55 | Correct | 4 ms | 5068 KB | Output is correct |
56 | Correct | 3 ms | 5068 KB | Output is correct |
57 | Correct | 4 ms | 5196 KB | Output is correct |
58 | Correct | 3 ms | 5016 KB | Output is correct |
59 | Correct | 4 ms | 5008 KB | Output is correct |
60 | Correct | 4 ms | 5068 KB | Output is correct |
61 | Correct | 4 ms | 5068 KB | Output is correct |
62 | Correct | 4 ms | 5140 KB | Output is correct |
63 | Correct | 3 ms | 5012 KB | Output is correct |
64 | Correct | 123 ms | 14936 KB | Output is correct |
65 | Correct | 128 ms | 15000 KB | Output is correct |
66 | Correct | 152 ms | 15112 KB | Output is correct |
67 | Correct | 122 ms | 15028 KB | Output is correct |
68 | Correct | 123 ms | 15040 KB | Output is correct |
69 | Correct | 143 ms | 15036 KB | Output is correct |
70 | Correct | 120 ms | 15020 KB | Output is correct |
71 | Correct | 149 ms | 15008 KB | Output is correct |
72 | Correct | 132 ms | 15028 KB | Output is correct |
73 | Correct | 143 ms | 27592 KB | Output is correct |
74 | Correct | 181 ms | 27532 KB | Output is correct |
75 | Correct | 129 ms | 14804 KB | Output is correct |
76 | Correct | 115 ms | 14856 KB | Output is correct |
77 | Correct | 121 ms | 14864 KB | Output is correct |
78 | Correct | 156 ms | 14916 KB | Output is correct |
79 | Correct | 131 ms | 14976 KB | Output is correct |
80 | Correct | 127 ms | 14864 KB | Output is correct |
81 | Correct | 120 ms | 15288 KB | Output is correct |
82 | Correct | 125 ms | 15040 KB | Output is correct |
83 | Correct | 139 ms | 20368 KB | Output is correct |
84 | Correct | 133 ms | 22264 KB | Output is correct |
85 | Correct | 158 ms | 21956 KB | Output is correct |
86 | Correct | 120 ms | 16324 KB | Output is correct |
87 | Correct | 134 ms | 15968 KB | Output is correct |
88 | Correct | 137 ms | 16260 KB | Output is correct |
89 | Correct | 116 ms | 16196 KB | Output is correct |
90 | Correct | 125 ms | 16064 KB | Output is correct |
91 | Correct | 128 ms | 16196 KB | Output is correct |
92 | Correct | 118 ms | 16516 KB | Output is correct |
93 | Correct | 114 ms | 18904 KB | Output is correct |
94 | Correct | 137 ms | 20664 KB | Output is correct |
95 | Correct | 155 ms | 19360 KB | Output is correct |
96 | Correct | 121 ms | 17548 KB | Output is correct |
97 | Correct | 145 ms | 16100 KB | Output is correct |
98 | Correct | 119 ms | 15596 KB | Output is correct |
99 | Correct | 112 ms | 15368 KB | Output is correct |
100 | Correct | 114 ms | 18548 KB | Output is correct |
101 | Correct | 144 ms | 16452 KB | Output is correct |
102 | Correct | 116 ms | 15788 KB | Output is correct |
103 | Correct | 125 ms | 15572 KB | Output is correct |
104 | Correct | 85 ms | 15028 KB | Output is correct |
105 | Correct | 134 ms | 24420 KB | Output is correct |
106 | Correct | 82 ms | 15640 KB | Output is correct |
107 | Correct | 81 ms | 15596 KB | Output is correct |
108 | Correct | 139 ms | 28304 KB | Output is correct |
109 | Correct | 74 ms | 15060 KB | Output is correct |
110 | Correct | 183 ms | 28812 KB | Output is correct |
111 | Correct | 123 ms | 14868 KB | Output is correct |