/* * In the name of GOD */
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
#define F first
#define S second
#define mk make_pair
const int N = 201234;
vector <int> g[N];
int dp[N];
bool f[N];
void dfs (int v, int p = -1) {
dp[v] = f[v];
int sum1 = 0;
for (int u : g[v]) {
if (u != p) {
dfs (u, v);
sum1 += dp[u];
}
}
if (f[v]) {
dp[v] = max(dp[v], sum1 - 1);
} else {
dp[v] = max(dp[v], sum1);
}
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
int n;
cin >> n;
if (n > 2000)
return 0;
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
for (int i = 1; i <= n; i++) {
char c;
cin >> c;
f[i] = (c - '0');
}
int mx = 1;
for (int i = 1; i <= n; i++) {
if (!f[i])
continue;
dfs (i);
for (int j : g[i]) {
mx = max(mx, dp[j] + 1);
}
}
cout << mx;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5052 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
5048 KB |
Output is correct |
11 |
Correct |
2 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
5052 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
5048 KB |
Output is correct |
21 |
Correct |
2 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5052 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
5048 KB |
Output is correct |
11 |
Correct |
2 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
5052 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
5048 KB |
Output is correct |
21 |
Correct |
2 ms |
4948 KB |
Output is correct |
22 |
Correct |
37 ms |
5112 KB |
Output is correct |
23 |
Correct |
33 ms |
5076 KB |
Output is correct |
24 |
Correct |
29 ms |
5076 KB |
Output is correct |
25 |
Correct |
20 ms |
5152 KB |
Output is correct |
26 |
Correct |
12 ms |
5108 KB |
Output is correct |
27 |
Correct |
6 ms |
5064 KB |
Output is correct |
28 |
Correct |
3 ms |
5076 KB |
Output is correct |
29 |
Correct |
55 ms |
5276 KB |
Output is correct |
30 |
Correct |
31 ms |
5188 KB |
Output is correct |
31 |
Correct |
34 ms |
5128 KB |
Output is correct |
32 |
Correct |
19 ms |
5064 KB |
Output is correct |
33 |
Correct |
36 ms |
5144 KB |
Output is correct |
34 |
Correct |
21 ms |
5076 KB |
Output is correct |
35 |
Correct |
12 ms |
5076 KB |
Output is correct |
36 |
Correct |
7 ms |
5076 KB |
Output is correct |
37 |
Correct |
24 ms |
5152 KB |
Output is correct |
38 |
Correct |
18 ms |
5152 KB |
Output is correct |
39 |
Correct |
43 ms |
5204 KB |
Output is correct |
40 |
Correct |
25 ms |
5224 KB |
Output is correct |
41 |
Correct |
14 ms |
5212 KB |
Output is correct |
42 |
Correct |
22 ms |
5076 KB |
Output is correct |
43 |
Correct |
7 ms |
5076 KB |
Output is correct |
44 |
Correct |
40 ms |
5076 KB |
Output is correct |
45 |
Correct |
30 ms |
5076 KB |
Output is correct |
46 |
Correct |
22 ms |
5076 KB |
Output is correct |
47 |
Correct |
12 ms |
5172 KB |
Output is correct |
48 |
Correct |
40 ms |
5204 KB |
Output is correct |
49 |
Correct |
40 ms |
5204 KB |
Output is correct |
50 |
Correct |
39 ms |
5188 KB |
Output is correct |
51 |
Correct |
39 ms |
5164 KB |
Output is correct |
52 |
Correct |
38 ms |
5136 KB |
Output is correct |
53 |
Correct |
27 ms |
5076 KB |
Output is correct |
54 |
Correct |
42 ms |
5076 KB |
Output is correct |
55 |
Correct |
36 ms |
5068 KB |
Output is correct |
56 |
Correct |
3 ms |
5076 KB |
Output is correct |
57 |
Correct |
3 ms |
5188 KB |
Output is correct |
58 |
Correct |
28 ms |
5152 KB |
Output is correct |
59 |
Correct |
25 ms |
5060 KB |
Output is correct |
60 |
Correct |
4 ms |
5192 KB |
Output is correct |
61 |
Correct |
3 ms |
5076 KB |
Output is correct |
62 |
Correct |
3 ms |
5196 KB |
Output is correct |
63 |
Correct |
30 ms |
5076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5052 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
5048 KB |
Output is correct |
11 |
Correct |
2 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
5052 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
5048 KB |
Output is correct |
21 |
Correct |
2 ms |
4948 KB |
Output is correct |
22 |
Correct |
37 ms |
5112 KB |
Output is correct |
23 |
Correct |
33 ms |
5076 KB |
Output is correct |
24 |
Correct |
29 ms |
5076 KB |
Output is correct |
25 |
Correct |
20 ms |
5152 KB |
Output is correct |
26 |
Correct |
12 ms |
5108 KB |
Output is correct |
27 |
Correct |
6 ms |
5064 KB |
Output is correct |
28 |
Correct |
3 ms |
5076 KB |
Output is correct |
29 |
Correct |
55 ms |
5276 KB |
Output is correct |
30 |
Correct |
31 ms |
5188 KB |
Output is correct |
31 |
Correct |
34 ms |
5128 KB |
Output is correct |
32 |
Correct |
19 ms |
5064 KB |
Output is correct |
33 |
Correct |
36 ms |
5144 KB |
Output is correct |
34 |
Correct |
21 ms |
5076 KB |
Output is correct |
35 |
Correct |
12 ms |
5076 KB |
Output is correct |
36 |
Correct |
7 ms |
5076 KB |
Output is correct |
37 |
Correct |
24 ms |
5152 KB |
Output is correct |
38 |
Correct |
18 ms |
5152 KB |
Output is correct |
39 |
Correct |
43 ms |
5204 KB |
Output is correct |
40 |
Correct |
25 ms |
5224 KB |
Output is correct |
41 |
Correct |
14 ms |
5212 KB |
Output is correct |
42 |
Correct |
22 ms |
5076 KB |
Output is correct |
43 |
Correct |
7 ms |
5076 KB |
Output is correct |
44 |
Correct |
40 ms |
5076 KB |
Output is correct |
45 |
Correct |
30 ms |
5076 KB |
Output is correct |
46 |
Correct |
22 ms |
5076 KB |
Output is correct |
47 |
Correct |
12 ms |
5172 KB |
Output is correct |
48 |
Correct |
40 ms |
5204 KB |
Output is correct |
49 |
Correct |
40 ms |
5204 KB |
Output is correct |
50 |
Correct |
39 ms |
5188 KB |
Output is correct |
51 |
Correct |
39 ms |
5164 KB |
Output is correct |
52 |
Correct |
38 ms |
5136 KB |
Output is correct |
53 |
Correct |
27 ms |
5076 KB |
Output is correct |
54 |
Correct |
42 ms |
5076 KB |
Output is correct |
55 |
Correct |
36 ms |
5068 KB |
Output is correct |
56 |
Correct |
3 ms |
5076 KB |
Output is correct |
57 |
Correct |
3 ms |
5188 KB |
Output is correct |
58 |
Correct |
28 ms |
5152 KB |
Output is correct |
59 |
Correct |
25 ms |
5060 KB |
Output is correct |
60 |
Correct |
4 ms |
5192 KB |
Output is correct |
61 |
Correct |
3 ms |
5076 KB |
Output is correct |
62 |
Correct |
3 ms |
5196 KB |
Output is correct |
63 |
Correct |
30 ms |
5076 KB |
Output is correct |
64 |
Incorrect |
2 ms |
5076 KB |
Output isn't correct |
65 |
Halted |
0 ms |
0 KB |
- |