/**
____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N_MAX = 200000;
int N;
vector <int> adj[N_MAX + 2];
bool plant[N_MAX + 2];
int dp[N_MAX + 2];
void dfs (int u, int parent = -1) {
dp[u] = 0;
for (int v : adj[u]) {
if (v != parent) {
dfs(v, u);
dp[u] += dp[v];
}
}
if (plant[u] == true) {
dp[u] = max(dp[u] - 1, 1);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N;
for (int i = 1; i <= N - 1; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
string str;
cin >> str;
for (int u = 1; u <= N; u++) {
plant[u] = (str[u - 1] == '1');
}
int cntPlants = 0;
for (int u = 1; u <= N; u++) {
cntPlants += plant[u];
}
int answer = min(cntPlants, 2);
for (int r = 1; r <= N; r++) {
dfs(r);
answer = max(answer, dp[r]);
}
cout << answer << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4980 KB |
Output is correct |
4 |
Correct |
2 ms |
4940 KB |
Output is correct |
5 |
Correct |
2 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
4 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
2 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
2 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
5016 KB |
Output is correct |
14 |
Correct |
2 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
2 ms |
4940 KB |
Output is correct |
17 |
Correct |
2 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
2 ms |
4940 KB |
Output is correct |
20 |
Correct |
2 ms |
4940 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 |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4980 KB |
Output is correct |
4 |
Correct |
2 ms |
4940 KB |
Output is correct |
5 |
Correct |
2 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
4 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
2 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
2 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
5016 KB |
Output is correct |
14 |
Correct |
2 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
2 ms |
4940 KB |
Output is correct |
17 |
Correct |
2 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
2 ms |
4940 KB |
Output is correct |
20 |
Correct |
2 ms |
4940 KB |
Output is correct |
21 |
Correct |
3 ms |
4940 KB |
Output is correct |
22 |
Correct |
69 ms |
5188 KB |
Output is correct |
23 |
Correct |
75 ms |
5072 KB |
Output is correct |
24 |
Correct |
70 ms |
5080 KB |
Output is correct |
25 |
Correct |
68 ms |
5076 KB |
Output is correct |
26 |
Correct |
66 ms |
5080 KB |
Output is correct |
27 |
Correct |
65 ms |
5068 KB |
Output is correct |
28 |
Correct |
72 ms |
5080 KB |
Output is correct |
29 |
Correct |
85 ms |
5196 KB |
Output is correct |
30 |
Correct |
84 ms |
5224 KB |
Output is correct |
31 |
Correct |
59 ms |
5068 KB |
Output is correct |
32 |
Correct |
61 ms |
5076 KB |
Output is correct |
33 |
Correct |
69 ms |
5092 KB |
Output is correct |
34 |
Correct |
72 ms |
5088 KB |
Output is correct |
35 |
Correct |
69 ms |
5072 KB |
Output is correct |
36 |
Correct |
69 ms |
5068 KB |
Output is correct |
37 |
Correct |
71 ms |
5080 KB |
Output is correct |
38 |
Correct |
65 ms |
5068 KB |
Output is correct |
39 |
Correct |
74 ms |
5068 KB |
Output is correct |
40 |
Correct |
82 ms |
5148 KB |
Output is correct |
41 |
Correct |
79 ms |
5156 KB |
Output is correct |
42 |
Correct |
74 ms |
5116 KB |
Output is correct |
43 |
Correct |
79 ms |
5068 KB |
Output is correct |
44 |
Correct |
59 ms |
5068 KB |
Output is correct |
45 |
Correct |
62 ms |
5068 KB |
Output is correct |
46 |
Correct |
63 ms |
5068 KB |
Output is correct |
47 |
Correct |
60 ms |
5108 KB |
Output is correct |
48 |
Correct |
56 ms |
5068 KB |
Output is correct |
49 |
Correct |
58 ms |
5156 KB |
Output is correct |
50 |
Correct |
57 ms |
5132 KB |
Output is correct |
51 |
Correct |
56 ms |
5132 KB |
Output is correct |
52 |
Correct |
64 ms |
5068 KB |
Output is correct |
53 |
Correct |
59 ms |
5132 KB |
Output is correct |
54 |
Correct |
61 ms |
5116 KB |
Output is correct |
55 |
Correct |
67 ms |
5188 KB |
Output is correct |
56 |
Correct |
30 ms |
5068 KB |
Output is correct |
57 |
Correct |
87 ms |
5224 KB |
Output is correct |
58 |
Correct |
32 ms |
5068 KB |
Output is correct |
59 |
Correct |
32 ms |
5068 KB |
Output is correct |
60 |
Correct |
87 ms |
5224 KB |
Output is correct |
61 |
Correct |
31 ms |
5112 KB |
Output is correct |
62 |
Correct |
87 ms |
5228 KB |
Output is correct |
63 |
Correct |
54 ms |
5076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4980 KB |
Output is correct |
4 |
Correct |
2 ms |
4940 KB |
Output is correct |
5 |
Correct |
2 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
4 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
2 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
2 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
5016 KB |
Output is correct |
14 |
Correct |
2 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
2 ms |
4940 KB |
Output is correct |
17 |
Correct |
2 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
2 ms |
4940 KB |
Output is correct |
20 |
Correct |
2 ms |
4940 KB |
Output is correct |
21 |
Correct |
3 ms |
4940 KB |
Output is correct |
22 |
Correct |
69 ms |
5188 KB |
Output is correct |
23 |
Correct |
75 ms |
5072 KB |
Output is correct |
24 |
Correct |
70 ms |
5080 KB |
Output is correct |
25 |
Correct |
68 ms |
5076 KB |
Output is correct |
26 |
Correct |
66 ms |
5080 KB |
Output is correct |
27 |
Correct |
65 ms |
5068 KB |
Output is correct |
28 |
Correct |
72 ms |
5080 KB |
Output is correct |
29 |
Correct |
85 ms |
5196 KB |
Output is correct |
30 |
Correct |
84 ms |
5224 KB |
Output is correct |
31 |
Correct |
59 ms |
5068 KB |
Output is correct |
32 |
Correct |
61 ms |
5076 KB |
Output is correct |
33 |
Correct |
69 ms |
5092 KB |
Output is correct |
34 |
Correct |
72 ms |
5088 KB |
Output is correct |
35 |
Correct |
69 ms |
5072 KB |
Output is correct |
36 |
Correct |
69 ms |
5068 KB |
Output is correct |
37 |
Correct |
71 ms |
5080 KB |
Output is correct |
38 |
Correct |
65 ms |
5068 KB |
Output is correct |
39 |
Correct |
74 ms |
5068 KB |
Output is correct |
40 |
Correct |
82 ms |
5148 KB |
Output is correct |
41 |
Correct |
79 ms |
5156 KB |
Output is correct |
42 |
Correct |
74 ms |
5116 KB |
Output is correct |
43 |
Correct |
79 ms |
5068 KB |
Output is correct |
44 |
Correct |
59 ms |
5068 KB |
Output is correct |
45 |
Correct |
62 ms |
5068 KB |
Output is correct |
46 |
Correct |
63 ms |
5068 KB |
Output is correct |
47 |
Correct |
60 ms |
5108 KB |
Output is correct |
48 |
Correct |
56 ms |
5068 KB |
Output is correct |
49 |
Correct |
58 ms |
5156 KB |
Output is correct |
50 |
Correct |
57 ms |
5132 KB |
Output is correct |
51 |
Correct |
56 ms |
5132 KB |
Output is correct |
52 |
Correct |
64 ms |
5068 KB |
Output is correct |
53 |
Correct |
59 ms |
5132 KB |
Output is correct |
54 |
Correct |
61 ms |
5116 KB |
Output is correct |
55 |
Correct |
67 ms |
5188 KB |
Output is correct |
56 |
Correct |
30 ms |
5068 KB |
Output is correct |
57 |
Correct |
87 ms |
5224 KB |
Output is correct |
58 |
Correct |
32 ms |
5068 KB |
Output is correct |
59 |
Correct |
32 ms |
5068 KB |
Output is correct |
60 |
Correct |
87 ms |
5224 KB |
Output is correct |
61 |
Correct |
31 ms |
5112 KB |
Output is correct |
62 |
Correct |
87 ms |
5228 KB |
Output is correct |
63 |
Correct |
54 ms |
5076 KB |
Output is correct |
64 |
Execution timed out |
1587 ms |
12668 KB |
Time limit exceeded |
65 |
Halted |
0 ms |
0 KB |
- |