#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define endl "\n"
#define int long long
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
const int N = 2e5 + 5;
vector<int> v[N];
string s;
int dp[N];
int ans;
void dfs(int c,int p){
int cur=0,sum=0;
for(int x:v[c]){
if(x==p) continue;
dfs(x,c);
cur=max(cur,dp[x]);
sum+=dp[x];
}
if(s[c]=='1'){
ans=max(ans,sum-1);
ans=max(ans,cur+1);
ans=max(ans,1LL);
}
else ans=max(ans,sum);
if(s[c]=='1') dp[c]=max(1LL,sum-1);
else dp[c]=sum;
}
void solve(){
int n;
cin >> n;
for(int i=1;i<n;i++){
int a,b;
cin >> a >> b;
v[a].pb(b);
v[b].pb(a);
}
cin >> s;
s = " " + s;
dfs(1,0);
cout << ans << endl;
}
int32_t main(){
cin.tie(0); ios::sync_with_stdio(0);
int t=1;//cin >> t;
while(t--) solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6548 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
6548 KB |
Output is correct |
5 |
Correct |
2 ms |
6488 KB |
Output is correct |
6 |
Correct |
2 ms |
6492 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
3 ms |
6492 KB |
Output is correct |
9 |
Correct |
2 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
6492 KB |
Output is correct |
11 |
Correct |
2 ms |
6492 KB |
Output is correct |
12 |
Correct |
2 ms |
6492 KB |
Output is correct |
13 |
Correct |
3 ms |
6492 KB |
Output is correct |
14 |
Correct |
2 ms |
6492 KB |
Output is correct |
15 |
Correct |
2 ms |
6744 KB |
Output is correct |
16 |
Correct |
2 ms |
6492 KB |
Output is correct |
17 |
Correct |
2 ms |
6492 KB |
Output is correct |
18 |
Correct |
2 ms |
6492 KB |
Output is correct |
19 |
Correct |
2 ms |
6492 KB |
Output is correct |
20 |
Correct |
2 ms |
6544 KB |
Output is correct |
21 |
Correct |
2 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6548 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
6548 KB |
Output is correct |
5 |
Correct |
2 ms |
6488 KB |
Output is correct |
6 |
Correct |
2 ms |
6492 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
3 ms |
6492 KB |
Output is correct |
9 |
Correct |
2 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
6492 KB |
Output is correct |
11 |
Correct |
2 ms |
6492 KB |
Output is correct |
12 |
Correct |
2 ms |
6492 KB |
Output is correct |
13 |
Correct |
3 ms |
6492 KB |
Output is correct |
14 |
Correct |
2 ms |
6492 KB |
Output is correct |
15 |
Correct |
2 ms |
6744 KB |
Output is correct |
16 |
Correct |
2 ms |
6492 KB |
Output is correct |
17 |
Correct |
2 ms |
6492 KB |
Output is correct |
18 |
Correct |
2 ms |
6492 KB |
Output is correct |
19 |
Correct |
2 ms |
6492 KB |
Output is correct |
20 |
Correct |
2 ms |
6544 KB |
Output is correct |
21 |
Correct |
2 ms |
6492 KB |
Output is correct |
22 |
Correct |
2 ms |
6492 KB |
Output is correct |
23 |
Correct |
2 ms |
6488 KB |
Output is correct |
24 |
Correct |
2 ms |
6664 KB |
Output is correct |
25 |
Correct |
2 ms |
6492 KB |
Output is correct |
26 |
Correct |
2 ms |
6492 KB |
Output is correct |
27 |
Correct |
2 ms |
6492 KB |
Output is correct |
28 |
Correct |
2 ms |
6492 KB |
Output is correct |
29 |
Correct |
2 ms |
6748 KB |
Output is correct |
30 |
Correct |
3 ms |
6488 KB |
Output is correct |
31 |
Correct |
2 ms |
6492 KB |
Output is correct |
32 |
Correct |
2 ms |
6492 KB |
Output is correct |
33 |
Correct |
2 ms |
6492 KB |
Output is correct |
34 |
Correct |
2 ms |
6492 KB |
Output is correct |
35 |
Correct |
3 ms |
6492 KB |
Output is correct |
36 |
Correct |
2 ms |
6492 KB |
Output is correct |
37 |
Correct |
3 ms |
6492 KB |
Output is correct |
38 |
Correct |
2 ms |
6492 KB |
Output is correct |
39 |
Correct |
2 ms |
6708 KB |
Output is correct |
40 |
Correct |
2 ms |
6488 KB |
Output is correct |
41 |
Correct |
2 ms |
6492 KB |
Output is correct |
42 |
Correct |
2 ms |
6492 KB |
Output is correct |
43 |
Correct |
2 ms |
6492 KB |
Output is correct |
44 |
Correct |
2 ms |
6492 KB |
Output is correct |
45 |
Correct |
2 ms |
6488 KB |
Output is correct |
46 |
Correct |
2 ms |
6492 KB |
Output is correct |
47 |
Correct |
2 ms |
6492 KB |
Output is correct |
48 |
Correct |
2 ms |
6492 KB |
Output is correct |
49 |
Correct |
2 ms |
6556 KB |
Output is correct |
50 |
Correct |
2 ms |
6492 KB |
Output is correct |
51 |
Correct |
2 ms |
6492 KB |
Output is correct |
52 |
Correct |
2 ms |
6492 KB |
Output is correct |
53 |
Correct |
2 ms |
6492 KB |
Output is correct |
54 |
Correct |
2 ms |
6492 KB |
Output is correct |
55 |
Correct |
2 ms |
6560 KB |
Output is correct |
56 |
Correct |
2 ms |
6492 KB |
Output is correct |
57 |
Correct |
2 ms |
6744 KB |
Output is correct |
58 |
Correct |
2 ms |
6492 KB |
Output is correct |
59 |
Correct |
2 ms |
6492 KB |
Output is correct |
60 |
Correct |
2 ms |
6740 KB |
Output is correct |
61 |
Correct |
2 ms |
6644 KB |
Output is correct |
62 |
Correct |
2 ms |
6748 KB |
Output is correct |
63 |
Correct |
2 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6548 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
6548 KB |
Output is correct |
5 |
Correct |
2 ms |
6488 KB |
Output is correct |
6 |
Correct |
2 ms |
6492 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
3 ms |
6492 KB |
Output is correct |
9 |
Correct |
2 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
6492 KB |
Output is correct |
11 |
Correct |
2 ms |
6492 KB |
Output is correct |
12 |
Correct |
2 ms |
6492 KB |
Output is correct |
13 |
Correct |
3 ms |
6492 KB |
Output is correct |
14 |
Correct |
2 ms |
6492 KB |
Output is correct |
15 |
Correct |
2 ms |
6744 KB |
Output is correct |
16 |
Correct |
2 ms |
6492 KB |
Output is correct |
17 |
Correct |
2 ms |
6492 KB |
Output is correct |
18 |
Correct |
2 ms |
6492 KB |
Output is correct |
19 |
Correct |
2 ms |
6492 KB |
Output is correct |
20 |
Correct |
2 ms |
6544 KB |
Output is correct |
21 |
Correct |
2 ms |
6492 KB |
Output is correct |
22 |
Correct |
2 ms |
6492 KB |
Output is correct |
23 |
Correct |
2 ms |
6488 KB |
Output is correct |
24 |
Correct |
2 ms |
6664 KB |
Output is correct |
25 |
Correct |
2 ms |
6492 KB |
Output is correct |
26 |
Correct |
2 ms |
6492 KB |
Output is correct |
27 |
Correct |
2 ms |
6492 KB |
Output is correct |
28 |
Correct |
2 ms |
6492 KB |
Output is correct |
29 |
Correct |
2 ms |
6748 KB |
Output is correct |
30 |
Correct |
3 ms |
6488 KB |
Output is correct |
31 |
Correct |
2 ms |
6492 KB |
Output is correct |
32 |
Correct |
2 ms |
6492 KB |
Output is correct |
33 |
Correct |
2 ms |
6492 KB |
Output is correct |
34 |
Correct |
2 ms |
6492 KB |
Output is correct |
35 |
Correct |
3 ms |
6492 KB |
Output is correct |
36 |
Correct |
2 ms |
6492 KB |
Output is correct |
37 |
Correct |
3 ms |
6492 KB |
Output is correct |
38 |
Correct |
2 ms |
6492 KB |
Output is correct |
39 |
Correct |
2 ms |
6708 KB |
Output is correct |
40 |
Correct |
2 ms |
6488 KB |
Output is correct |
41 |
Correct |
2 ms |
6492 KB |
Output is correct |
42 |
Correct |
2 ms |
6492 KB |
Output is correct |
43 |
Correct |
2 ms |
6492 KB |
Output is correct |
44 |
Correct |
2 ms |
6492 KB |
Output is correct |
45 |
Correct |
2 ms |
6488 KB |
Output is correct |
46 |
Correct |
2 ms |
6492 KB |
Output is correct |
47 |
Correct |
2 ms |
6492 KB |
Output is correct |
48 |
Correct |
2 ms |
6492 KB |
Output is correct |
49 |
Correct |
2 ms |
6556 KB |
Output is correct |
50 |
Correct |
2 ms |
6492 KB |
Output is correct |
51 |
Correct |
2 ms |
6492 KB |
Output is correct |
52 |
Correct |
2 ms |
6492 KB |
Output is correct |
53 |
Correct |
2 ms |
6492 KB |
Output is correct |
54 |
Correct |
2 ms |
6492 KB |
Output is correct |
55 |
Correct |
2 ms |
6560 KB |
Output is correct |
56 |
Correct |
2 ms |
6492 KB |
Output is correct |
57 |
Correct |
2 ms |
6744 KB |
Output is correct |
58 |
Correct |
2 ms |
6492 KB |
Output is correct |
59 |
Correct |
2 ms |
6492 KB |
Output is correct |
60 |
Correct |
2 ms |
6740 KB |
Output is correct |
61 |
Correct |
2 ms |
6644 KB |
Output is correct |
62 |
Correct |
2 ms |
6748 KB |
Output is correct |
63 |
Correct |
2 ms |
6492 KB |
Output is correct |
64 |
Correct |
127 ms |
17088 KB |
Output is correct |
65 |
Correct |
64 ms |
17100 KB |
Output is correct |
66 |
Correct |
62 ms |
17084 KB |
Output is correct |
67 |
Correct |
82 ms |
17040 KB |
Output is correct |
68 |
Correct |
63 ms |
17088 KB |
Output is correct |
69 |
Correct |
96 ms |
17044 KB |
Output is correct |
70 |
Correct |
89 ms |
16952 KB |
Output is correct |
71 |
Correct |
62 ms |
17056 KB |
Output is correct |
72 |
Correct |
86 ms |
17036 KB |
Output is correct |
73 |
Correct |
125 ms |
28684 KB |
Output is correct |
74 |
Correct |
104 ms |
28480 KB |
Output is correct |
75 |
Correct |
86 ms |
18316 KB |
Output is correct |
76 |
Correct |
79 ms |
18228 KB |
Output is correct |
77 |
Correct |
63 ms |
17036 KB |
Output is correct |
78 |
Correct |
90 ms |
17040 KB |
Output is correct |
79 |
Correct |
66 ms |
16968 KB |
Output is correct |
80 |
Correct |
67 ms |
17024 KB |
Output is correct |
81 |
Correct |
54 ms |
16992 KB |
Output is correct |
82 |
Correct |
65 ms |
16900 KB |
Output is correct |
83 |
Correct |
99 ms |
22092 KB |
Output is correct |
84 |
Correct |
87 ms |
24284 KB |
Output is correct |
85 |
Correct |
124 ms |
23844 KB |
Output is correct |
86 |
Correct |
65 ms |
18380 KB |
Output is correct |
87 |
Correct |
64 ms |
17684 KB |
Output is correct |
88 |
Correct |
63 ms |
17932 KB |
Output is correct |
89 |
Correct |
64 ms |
17808 KB |
Output is correct |
90 |
Correct |
68 ms |
17716 KB |
Output is correct |
91 |
Correct |
70 ms |
17784 KB |
Output is correct |
92 |
Correct |
77 ms |
18108 KB |
Output is correct |
93 |
Correct |
79 ms |
20428 KB |
Output is correct |
94 |
Correct |
77 ms |
22212 KB |
Output is correct |
95 |
Correct |
81 ms |
20804 KB |
Output is correct |
96 |
Correct |
81 ms |
18928 KB |
Output is correct |
97 |
Correct |
74 ms |
17620 KB |
Output is correct |
98 |
Correct |
60 ms |
17148 KB |
Output is correct |
99 |
Correct |
81 ms |
17368 KB |
Output is correct |
100 |
Correct |
86 ms |
19900 KB |
Output is correct |
101 |
Correct |
84 ms |
17920 KB |
Output is correct |
102 |
Correct |
62 ms |
17312 KB |
Output is correct |
103 |
Correct |
62 ms |
17388 KB |
Output is correct |
104 |
Correct |
47 ms |
17600 KB |
Output is correct |
105 |
Correct |
99 ms |
25460 KB |
Output is correct |
106 |
Correct |
57 ms |
17672 KB |
Output is correct |
107 |
Correct |
42 ms |
17600 KB |
Output is correct |
108 |
Correct |
104 ms |
29388 KB |
Output is correct |
109 |
Correct |
61 ms |
17604 KB |
Output is correct |
110 |
Correct |
80 ms |
29648 KB |
Output is correct |
111 |
Correct |
92 ms |
17056 KB |
Output is correct |