#include <bits/stdc++.h>
using namespace std;
const int mxn = 2e5+5;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef pair<int,pii>piii;
#define sf scanf
#define pf printf
#define input freopen("in.txt","r",stdin)
#define output freopen("out.txt","w",stdout)
#define inf 1e18
#define ff first
#define ss second
#define MP make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define printcase(cases) printf("Case %d:", cases);
#define Unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define FAST ios_base::sync_with_stdio(0);cout.tie(0)
#define endl printf("\n")
#define __lcm(a, b) ((a*b)/__gcd(a, b))
int arr[mxn];
vector<int>adj[mxn];
int dp[mxn];
int ans = 0;
void dfs(int u, int p)
{
int mx = 0;
for(auto v : adj[u])
{
if(v==p) continue;
dfs(v, u);
dp[u]+=dp[v];
mx = max(mx, dp[v]);
}
if(arr[u])
{
ans = max(ans, mx+1);
dp[u] = max(1, dp[u]-1);
}
ans = max(ans, dp[u]);
}
int main()
{
// input;
//output;
int n;
cin >> n;
for(int i = 1; i < n; i++)
{
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
string s;
cin >> s;
for(int i = 0; i < n; i++) arr[i+1] = s[i]-'0';
dfs(1, 1);
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
3 ms |
4992 KB |
Output is correct |
4 |
Correct |
3 ms |
4992 KB |
Output is correct |
5 |
Correct |
3 ms |
4992 KB |
Output is correct |
6 |
Correct |
3 ms |
4992 KB |
Output is correct |
7 |
Correct |
3 ms |
4992 KB |
Output is correct |
8 |
Correct |
3 ms |
4992 KB |
Output is correct |
9 |
Correct |
3 ms |
4992 KB |
Output is correct |
10 |
Correct |
3 ms |
4992 KB |
Output is correct |
11 |
Correct |
3 ms |
4992 KB |
Output is correct |
12 |
Correct |
3 ms |
4992 KB |
Output is correct |
13 |
Correct |
4 ms |
4992 KB |
Output is correct |
14 |
Correct |
3 ms |
4992 KB |
Output is correct |
15 |
Correct |
4 ms |
4992 KB |
Output is correct |
16 |
Correct |
3 ms |
4992 KB |
Output is correct |
17 |
Correct |
3 ms |
4992 KB |
Output is correct |
18 |
Correct |
3 ms |
4992 KB |
Output is correct |
19 |
Correct |
3 ms |
4992 KB |
Output is correct |
20 |
Correct |
4 ms |
4992 KB |
Output is correct |
21 |
Correct |
3 ms |
4992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
3 ms |
4992 KB |
Output is correct |
4 |
Correct |
3 ms |
4992 KB |
Output is correct |
5 |
Correct |
3 ms |
4992 KB |
Output is correct |
6 |
Correct |
3 ms |
4992 KB |
Output is correct |
7 |
Correct |
3 ms |
4992 KB |
Output is correct |
8 |
Correct |
3 ms |
4992 KB |
Output is correct |
9 |
Correct |
3 ms |
4992 KB |
Output is correct |
10 |
Correct |
3 ms |
4992 KB |
Output is correct |
11 |
Correct |
3 ms |
4992 KB |
Output is correct |
12 |
Correct |
3 ms |
4992 KB |
Output is correct |
13 |
Correct |
4 ms |
4992 KB |
Output is correct |
14 |
Correct |
3 ms |
4992 KB |
Output is correct |
15 |
Correct |
4 ms |
4992 KB |
Output is correct |
16 |
Correct |
3 ms |
4992 KB |
Output is correct |
17 |
Correct |
3 ms |
4992 KB |
Output is correct |
18 |
Correct |
3 ms |
4992 KB |
Output is correct |
19 |
Correct |
3 ms |
4992 KB |
Output is correct |
20 |
Correct |
4 ms |
4992 KB |
Output is correct |
21 |
Correct |
3 ms |
4992 KB |
Output is correct |
22 |
Correct |
5 ms |
5120 KB |
Output is correct |
23 |
Correct |
6 ms |
5120 KB |
Output is correct |
24 |
Correct |
6 ms |
5120 KB |
Output is correct |
25 |
Correct |
6 ms |
5120 KB |
Output is correct |
26 |
Correct |
6 ms |
5120 KB |
Output is correct |
27 |
Correct |
6 ms |
5120 KB |
Output is correct |
28 |
Correct |
6 ms |
5120 KB |
Output is correct |
29 |
Correct |
6 ms |
5376 KB |
Output is correct |
30 |
Correct |
6 ms |
5248 KB |
Output is correct |
31 |
Correct |
6 ms |
5120 KB |
Output is correct |
32 |
Correct |
6 ms |
5120 KB |
Output is correct |
33 |
Correct |
7 ms |
5120 KB |
Output is correct |
34 |
Correct |
6 ms |
5120 KB |
Output is correct |
35 |
Correct |
6 ms |
5120 KB |
Output is correct |
36 |
Correct |
6 ms |
5120 KB |
Output is correct |
37 |
Correct |
5 ms |
5120 KB |
Output is correct |
38 |
Correct |
6 ms |
5120 KB |
Output is correct |
39 |
Correct |
6 ms |
5120 KB |
Output is correct |
40 |
Correct |
5 ms |
5120 KB |
Output is correct |
41 |
Correct |
6 ms |
5120 KB |
Output is correct |
42 |
Correct |
7 ms |
5120 KB |
Output is correct |
43 |
Correct |
6 ms |
5120 KB |
Output is correct |
44 |
Correct |
5 ms |
5120 KB |
Output is correct |
45 |
Correct |
6 ms |
5120 KB |
Output is correct |
46 |
Correct |
6 ms |
5120 KB |
Output is correct |
47 |
Correct |
6 ms |
5120 KB |
Output is correct |
48 |
Correct |
6 ms |
5120 KB |
Output is correct |
49 |
Correct |
6 ms |
5120 KB |
Output is correct |
50 |
Correct |
6 ms |
5120 KB |
Output is correct |
51 |
Correct |
6 ms |
5120 KB |
Output is correct |
52 |
Correct |
6 ms |
5120 KB |
Output is correct |
53 |
Correct |
6 ms |
5120 KB |
Output is correct |
54 |
Correct |
6 ms |
5120 KB |
Output is correct |
55 |
Correct |
5 ms |
5120 KB |
Output is correct |
56 |
Correct |
5 ms |
5120 KB |
Output is correct |
57 |
Correct |
6 ms |
5248 KB |
Output is correct |
58 |
Correct |
5 ms |
5120 KB |
Output is correct |
59 |
Correct |
5 ms |
5120 KB |
Output is correct |
60 |
Correct |
6 ms |
5120 KB |
Output is correct |
61 |
Correct |
6 ms |
5120 KB |
Output is correct |
62 |
Correct |
6 ms |
5248 KB |
Output is correct |
63 |
Correct |
6 ms |
5120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
3 ms |
4992 KB |
Output is correct |
4 |
Correct |
3 ms |
4992 KB |
Output is correct |
5 |
Correct |
3 ms |
4992 KB |
Output is correct |
6 |
Correct |
3 ms |
4992 KB |
Output is correct |
7 |
Correct |
3 ms |
4992 KB |
Output is correct |
8 |
Correct |
3 ms |
4992 KB |
Output is correct |
9 |
Correct |
3 ms |
4992 KB |
Output is correct |
10 |
Correct |
3 ms |
4992 KB |
Output is correct |
11 |
Correct |
3 ms |
4992 KB |
Output is correct |
12 |
Correct |
3 ms |
4992 KB |
Output is correct |
13 |
Correct |
4 ms |
4992 KB |
Output is correct |
14 |
Correct |
3 ms |
4992 KB |
Output is correct |
15 |
Correct |
4 ms |
4992 KB |
Output is correct |
16 |
Correct |
3 ms |
4992 KB |
Output is correct |
17 |
Correct |
3 ms |
4992 KB |
Output is correct |
18 |
Correct |
3 ms |
4992 KB |
Output is correct |
19 |
Correct |
3 ms |
4992 KB |
Output is correct |
20 |
Correct |
4 ms |
4992 KB |
Output is correct |
21 |
Correct |
3 ms |
4992 KB |
Output is correct |
22 |
Correct |
5 ms |
5120 KB |
Output is correct |
23 |
Correct |
6 ms |
5120 KB |
Output is correct |
24 |
Correct |
6 ms |
5120 KB |
Output is correct |
25 |
Correct |
6 ms |
5120 KB |
Output is correct |
26 |
Correct |
6 ms |
5120 KB |
Output is correct |
27 |
Correct |
6 ms |
5120 KB |
Output is correct |
28 |
Correct |
6 ms |
5120 KB |
Output is correct |
29 |
Correct |
6 ms |
5376 KB |
Output is correct |
30 |
Correct |
6 ms |
5248 KB |
Output is correct |
31 |
Correct |
6 ms |
5120 KB |
Output is correct |
32 |
Correct |
6 ms |
5120 KB |
Output is correct |
33 |
Correct |
7 ms |
5120 KB |
Output is correct |
34 |
Correct |
6 ms |
5120 KB |
Output is correct |
35 |
Correct |
6 ms |
5120 KB |
Output is correct |
36 |
Correct |
6 ms |
5120 KB |
Output is correct |
37 |
Correct |
5 ms |
5120 KB |
Output is correct |
38 |
Correct |
6 ms |
5120 KB |
Output is correct |
39 |
Correct |
6 ms |
5120 KB |
Output is correct |
40 |
Correct |
5 ms |
5120 KB |
Output is correct |
41 |
Correct |
6 ms |
5120 KB |
Output is correct |
42 |
Correct |
7 ms |
5120 KB |
Output is correct |
43 |
Correct |
6 ms |
5120 KB |
Output is correct |
44 |
Correct |
5 ms |
5120 KB |
Output is correct |
45 |
Correct |
6 ms |
5120 KB |
Output is correct |
46 |
Correct |
6 ms |
5120 KB |
Output is correct |
47 |
Correct |
6 ms |
5120 KB |
Output is correct |
48 |
Correct |
6 ms |
5120 KB |
Output is correct |
49 |
Correct |
6 ms |
5120 KB |
Output is correct |
50 |
Correct |
6 ms |
5120 KB |
Output is correct |
51 |
Correct |
6 ms |
5120 KB |
Output is correct |
52 |
Correct |
6 ms |
5120 KB |
Output is correct |
53 |
Correct |
6 ms |
5120 KB |
Output is correct |
54 |
Correct |
6 ms |
5120 KB |
Output is correct |
55 |
Correct |
5 ms |
5120 KB |
Output is correct |
56 |
Correct |
5 ms |
5120 KB |
Output is correct |
57 |
Correct |
6 ms |
5248 KB |
Output is correct |
58 |
Correct |
5 ms |
5120 KB |
Output is correct |
59 |
Correct |
5 ms |
5120 KB |
Output is correct |
60 |
Correct |
6 ms |
5120 KB |
Output is correct |
61 |
Correct |
6 ms |
5120 KB |
Output is correct |
62 |
Correct |
6 ms |
5248 KB |
Output is correct |
63 |
Correct |
6 ms |
5120 KB |
Output is correct |
64 |
Correct |
362 ms |
13324 KB |
Output is correct |
65 |
Correct |
366 ms |
13576 KB |
Output is correct |
66 |
Correct |
354 ms |
13316 KB |
Output is correct |
67 |
Correct |
359 ms |
13324 KB |
Output is correct |
68 |
Correct |
359 ms |
13316 KB |
Output is correct |
69 |
Correct |
358 ms |
13472 KB |
Output is correct |
70 |
Correct |
355 ms |
13320 KB |
Output is correct |
71 |
Correct |
355 ms |
13316 KB |
Output is correct |
72 |
Correct |
355 ms |
13320 KB |
Output is correct |
73 |
Correct |
372 ms |
25992 KB |
Output is correct |
74 |
Correct |
372 ms |
25864 KB |
Output is correct |
75 |
Correct |
352 ms |
13320 KB |
Output is correct |
76 |
Correct |
354 ms |
13448 KB |
Output is correct |
77 |
Correct |
353 ms |
13192 KB |
Output is correct |
78 |
Correct |
361 ms |
13196 KB |
Output is correct |
79 |
Correct |
362 ms |
13192 KB |
Output is correct |
80 |
Correct |
362 ms |
13192 KB |
Output is correct |
81 |
Correct |
334 ms |
13680 KB |
Output is correct |
82 |
Correct |
347 ms |
13684 KB |
Output is correct |
83 |
Correct |
371 ms |
18392 KB |
Output is correct |
84 |
Correct |
370 ms |
20492 KB |
Output is correct |
85 |
Correct |
371 ms |
20232 KB |
Output is correct |
86 |
Correct |
368 ms |
14600 KB |
Output is correct |
87 |
Correct |
362 ms |
14088 KB |
Output is correct |
88 |
Correct |
353 ms |
14472 KB |
Output is correct |
89 |
Correct |
363 ms |
14472 KB |
Output is correct |
90 |
Correct |
355 ms |
14216 KB |
Output is correct |
91 |
Correct |
351 ms |
14468 KB |
Output is correct |
92 |
Correct |
355 ms |
14804 KB |
Output is correct |
93 |
Correct |
342 ms |
17416 KB |
Output is correct |
94 |
Correct |
337 ms |
19056 KB |
Output is correct |
95 |
Correct |
338 ms |
17668 KB |
Output is correct |
96 |
Correct |
348 ms |
16008 KB |
Output is correct |
97 |
Correct |
347 ms |
14440 KB |
Output is correct |
98 |
Correct |
351 ms |
13832 KB |
Output is correct |
99 |
Correct |
351 ms |
13704 KB |
Output is correct |
100 |
Correct |
350 ms |
16904 KB |
Output is correct |
101 |
Correct |
348 ms |
14856 KB |
Output is correct |
102 |
Correct |
347 ms |
14088 KB |
Output is correct |
103 |
Correct |
355 ms |
13960 KB |
Output is correct |
104 |
Correct |
302 ms |
13292 KB |
Output is correct |
105 |
Correct |
373 ms |
22792 KB |
Output is correct |
106 |
Correct |
289 ms |
14060 KB |
Output is correct |
107 |
Correct |
288 ms |
14064 KB |
Output is correct |
108 |
Correct |
372 ms |
26632 KB |
Output is correct |
109 |
Correct |
300 ms |
13288 KB |
Output is correct |
110 |
Correct |
368 ms |
27012 KB |
Output is correct |
111 |
Correct |
347 ms |
13192 KB |
Output is correct |