#include <bits/stdc++.h>
using namespace std;
const long long MX=2e5+10;
vector < int > mas[MX];
int dp[MX];
char s[MX];
int ans=0;
void DFS(int zar,int mun)
{
int mx=0;
for(auto u:mas[zar])
{
if(u==mun)
{
continue;
}
DFS(u,zar);
dp[zar]+=max(0,dp[u]);
mx=max(mx,dp[u]);
}
dp[zar]=max((int)(s[zar]=='1'),(dp[zar]-(s[zar]=='1')));
if(s[zar]=='1')
{
ans=max(ans,mx+1);
}
ans=max(ans,dp[zar]);
return;
}
int main()
{
cin.tie(0);
ios_base::sync_with_stdio(0);
int n;
cin>>n;
int a,b;
for(int i=1;i<n;i++)
{
cin>>a>>b;
mas[a].push_back(b);
mas[b].push_back(a);
}
for(int i=1;i<=n;i++)
{
cin>>s[i];
}
DFS(1,0);
cout<<ans<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5720 KB |
Output is correct |
2 |
Correct |
1 ms |
5724 KB |
Output is correct |
3 |
Correct |
1 ms |
5724 KB |
Output is correct |
4 |
Correct |
1 ms |
5724 KB |
Output is correct |
5 |
Correct |
1 ms |
5884 KB |
Output is correct |
6 |
Correct |
2 ms |
5760 KB |
Output is correct |
7 |
Correct |
1 ms |
5724 KB |
Output is correct |
8 |
Correct |
1 ms |
5724 KB |
Output is correct |
9 |
Correct |
2 ms |
5724 KB |
Output is correct |
10 |
Correct |
2 ms |
5724 KB |
Output is correct |
11 |
Correct |
1 ms |
5724 KB |
Output is correct |
12 |
Correct |
2 ms |
5724 KB |
Output is correct |
13 |
Correct |
2 ms |
5724 KB |
Output is correct |
14 |
Correct |
2 ms |
5724 KB |
Output is correct |
15 |
Correct |
2 ms |
5720 KB |
Output is correct |
16 |
Correct |
1 ms |
5712 KB |
Output is correct |
17 |
Correct |
2 ms |
5724 KB |
Output is correct |
18 |
Correct |
2 ms |
5720 KB |
Output is correct |
19 |
Correct |
2 ms |
5724 KB |
Output is correct |
20 |
Correct |
2 ms |
5724 KB |
Output is correct |
21 |
Correct |
2 ms |
5724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5720 KB |
Output is correct |
2 |
Correct |
1 ms |
5724 KB |
Output is correct |
3 |
Correct |
1 ms |
5724 KB |
Output is correct |
4 |
Correct |
1 ms |
5724 KB |
Output is correct |
5 |
Correct |
1 ms |
5884 KB |
Output is correct |
6 |
Correct |
2 ms |
5760 KB |
Output is correct |
7 |
Correct |
1 ms |
5724 KB |
Output is correct |
8 |
Correct |
1 ms |
5724 KB |
Output is correct |
9 |
Correct |
2 ms |
5724 KB |
Output is correct |
10 |
Correct |
2 ms |
5724 KB |
Output is correct |
11 |
Correct |
1 ms |
5724 KB |
Output is correct |
12 |
Correct |
2 ms |
5724 KB |
Output is correct |
13 |
Correct |
2 ms |
5724 KB |
Output is correct |
14 |
Correct |
2 ms |
5724 KB |
Output is correct |
15 |
Correct |
2 ms |
5720 KB |
Output is correct |
16 |
Correct |
1 ms |
5712 KB |
Output is correct |
17 |
Correct |
2 ms |
5724 KB |
Output is correct |
18 |
Correct |
2 ms |
5720 KB |
Output is correct |
19 |
Correct |
2 ms |
5724 KB |
Output is correct |
20 |
Correct |
2 ms |
5724 KB |
Output is correct |
21 |
Correct |
2 ms |
5724 KB |
Output is correct |
22 |
Correct |
3 ms |
5980 KB |
Output is correct |
23 |
Correct |
2 ms |
5980 KB |
Output is correct |
24 |
Correct |
2 ms |
5960 KB |
Output is correct |
25 |
Correct |
2 ms |
5980 KB |
Output is correct |
26 |
Correct |
2 ms |
5980 KB |
Output is correct |
27 |
Correct |
2 ms |
5980 KB |
Output is correct |
28 |
Correct |
2 ms |
5976 KB |
Output is correct |
29 |
Correct |
2 ms |
5980 KB |
Output is correct |
30 |
Correct |
2 ms |
5908 KB |
Output is correct |
31 |
Correct |
3 ms |
5980 KB |
Output is correct |
32 |
Correct |
2 ms |
5976 KB |
Output is correct |
33 |
Correct |
2 ms |
5980 KB |
Output is correct |
34 |
Correct |
2 ms |
5968 KB |
Output is correct |
35 |
Correct |
2 ms |
5980 KB |
Output is correct |
36 |
Correct |
2 ms |
5980 KB |
Output is correct |
37 |
Correct |
2 ms |
5980 KB |
Output is correct |
38 |
Correct |
2 ms |
5964 KB |
Output is correct |
39 |
Correct |
2 ms |
5980 KB |
Output is correct |
40 |
Correct |
2 ms |
5980 KB |
Output is correct |
41 |
Correct |
2 ms |
6036 KB |
Output is correct |
42 |
Correct |
2 ms |
6232 KB |
Output is correct |
43 |
Correct |
2 ms |
5980 KB |
Output is correct |
44 |
Correct |
2 ms |
5980 KB |
Output is correct |
45 |
Correct |
2 ms |
5980 KB |
Output is correct |
46 |
Correct |
2 ms |
6236 KB |
Output is correct |
47 |
Correct |
2 ms |
5980 KB |
Output is correct |
48 |
Correct |
2 ms |
5964 KB |
Output is correct |
49 |
Correct |
2 ms |
5980 KB |
Output is correct |
50 |
Correct |
2 ms |
5980 KB |
Output is correct |
51 |
Correct |
2 ms |
5980 KB |
Output is correct |
52 |
Correct |
2 ms |
5980 KB |
Output is correct |
53 |
Correct |
2 ms |
5980 KB |
Output is correct |
54 |
Correct |
2 ms |
5980 KB |
Output is correct |
55 |
Correct |
2 ms |
5868 KB |
Output is correct |
56 |
Correct |
3 ms |
5944 KB |
Output is correct |
57 |
Correct |
2 ms |
5976 KB |
Output is correct |
58 |
Correct |
2 ms |
5980 KB |
Output is correct |
59 |
Correct |
2 ms |
5980 KB |
Output is correct |
60 |
Correct |
2 ms |
5980 KB |
Output is correct |
61 |
Correct |
2 ms |
5980 KB |
Output is correct |
62 |
Correct |
2 ms |
5980 KB |
Output is correct |
63 |
Correct |
2 ms |
5980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5720 KB |
Output is correct |
2 |
Correct |
1 ms |
5724 KB |
Output is correct |
3 |
Correct |
1 ms |
5724 KB |
Output is correct |
4 |
Correct |
1 ms |
5724 KB |
Output is correct |
5 |
Correct |
1 ms |
5884 KB |
Output is correct |
6 |
Correct |
2 ms |
5760 KB |
Output is correct |
7 |
Correct |
1 ms |
5724 KB |
Output is correct |
8 |
Correct |
1 ms |
5724 KB |
Output is correct |
9 |
Correct |
2 ms |
5724 KB |
Output is correct |
10 |
Correct |
2 ms |
5724 KB |
Output is correct |
11 |
Correct |
1 ms |
5724 KB |
Output is correct |
12 |
Correct |
2 ms |
5724 KB |
Output is correct |
13 |
Correct |
2 ms |
5724 KB |
Output is correct |
14 |
Correct |
2 ms |
5724 KB |
Output is correct |
15 |
Correct |
2 ms |
5720 KB |
Output is correct |
16 |
Correct |
1 ms |
5712 KB |
Output is correct |
17 |
Correct |
2 ms |
5724 KB |
Output is correct |
18 |
Correct |
2 ms |
5720 KB |
Output is correct |
19 |
Correct |
2 ms |
5724 KB |
Output is correct |
20 |
Correct |
2 ms |
5724 KB |
Output is correct |
21 |
Correct |
2 ms |
5724 KB |
Output is correct |
22 |
Correct |
3 ms |
5980 KB |
Output is correct |
23 |
Correct |
2 ms |
5980 KB |
Output is correct |
24 |
Correct |
2 ms |
5960 KB |
Output is correct |
25 |
Correct |
2 ms |
5980 KB |
Output is correct |
26 |
Correct |
2 ms |
5980 KB |
Output is correct |
27 |
Correct |
2 ms |
5980 KB |
Output is correct |
28 |
Correct |
2 ms |
5976 KB |
Output is correct |
29 |
Correct |
2 ms |
5980 KB |
Output is correct |
30 |
Correct |
2 ms |
5908 KB |
Output is correct |
31 |
Correct |
3 ms |
5980 KB |
Output is correct |
32 |
Correct |
2 ms |
5976 KB |
Output is correct |
33 |
Correct |
2 ms |
5980 KB |
Output is correct |
34 |
Correct |
2 ms |
5968 KB |
Output is correct |
35 |
Correct |
2 ms |
5980 KB |
Output is correct |
36 |
Correct |
2 ms |
5980 KB |
Output is correct |
37 |
Correct |
2 ms |
5980 KB |
Output is correct |
38 |
Correct |
2 ms |
5964 KB |
Output is correct |
39 |
Correct |
2 ms |
5980 KB |
Output is correct |
40 |
Correct |
2 ms |
5980 KB |
Output is correct |
41 |
Correct |
2 ms |
6036 KB |
Output is correct |
42 |
Correct |
2 ms |
6232 KB |
Output is correct |
43 |
Correct |
2 ms |
5980 KB |
Output is correct |
44 |
Correct |
2 ms |
5980 KB |
Output is correct |
45 |
Correct |
2 ms |
5980 KB |
Output is correct |
46 |
Correct |
2 ms |
6236 KB |
Output is correct |
47 |
Correct |
2 ms |
5980 KB |
Output is correct |
48 |
Correct |
2 ms |
5964 KB |
Output is correct |
49 |
Correct |
2 ms |
5980 KB |
Output is correct |
50 |
Correct |
2 ms |
5980 KB |
Output is correct |
51 |
Correct |
2 ms |
5980 KB |
Output is correct |
52 |
Correct |
2 ms |
5980 KB |
Output is correct |
53 |
Correct |
2 ms |
5980 KB |
Output is correct |
54 |
Correct |
2 ms |
5980 KB |
Output is correct |
55 |
Correct |
2 ms |
5868 KB |
Output is correct |
56 |
Correct |
3 ms |
5944 KB |
Output is correct |
57 |
Correct |
2 ms |
5976 KB |
Output is correct |
58 |
Correct |
2 ms |
5980 KB |
Output is correct |
59 |
Correct |
2 ms |
5980 KB |
Output is correct |
60 |
Correct |
2 ms |
5980 KB |
Output is correct |
61 |
Correct |
2 ms |
5980 KB |
Output is correct |
62 |
Correct |
2 ms |
5980 KB |
Output is correct |
63 |
Correct |
2 ms |
5980 KB |
Output is correct |
64 |
Correct |
91 ms |
15188 KB |
Output is correct |
65 |
Correct |
59 ms |
15188 KB |
Output is correct |
66 |
Correct |
58 ms |
14964 KB |
Output is correct |
67 |
Correct |
74 ms |
14988 KB |
Output is correct |
68 |
Correct |
59 ms |
15184 KB |
Output is correct |
69 |
Correct |
82 ms |
15092 KB |
Output is correct |
70 |
Correct |
57 ms |
15188 KB |
Output is correct |
71 |
Correct |
71 ms |
15044 KB |
Output is correct |
72 |
Correct |
55 ms |
15184 KB |
Output is correct |
73 |
Correct |
79 ms |
27728 KB |
Output is correct |
74 |
Correct |
75 ms |
27728 KB |
Output is correct |
75 |
Correct |
58 ms |
14928 KB |
Output is correct |
76 |
Correct |
57 ms |
14992 KB |
Output is correct |
77 |
Correct |
73 ms |
15092 KB |
Output is correct |
78 |
Correct |
55 ms |
14928 KB |
Output is correct |
79 |
Correct |
80 ms |
15132 KB |
Output is correct |
80 |
Correct |
73 ms |
15008 KB |
Output is correct |
81 |
Correct |
66 ms |
15220 KB |
Output is correct |
82 |
Correct |
55 ms |
15052 KB |
Output is correct |
83 |
Correct |
63 ms |
20196 KB |
Output is correct |
84 |
Correct |
67 ms |
22352 KB |
Output is correct |
85 |
Correct |
74 ms |
22096 KB |
Output is correct |
86 |
Correct |
68 ms |
16340 KB |
Output is correct |
87 |
Correct |
58 ms |
15796 KB |
Output is correct |
88 |
Correct |
73 ms |
16284 KB |
Output is correct |
89 |
Correct |
58 ms |
16212 KB |
Output is correct |
90 |
Correct |
61 ms |
16160 KB |
Output is correct |
91 |
Correct |
64 ms |
16452 KB |
Output is correct |
92 |
Correct |
60 ms |
16724 KB |
Output is correct |
93 |
Correct |
60 ms |
19152 KB |
Output is correct |
94 |
Correct |
58 ms |
20684 KB |
Output is correct |
95 |
Correct |
63 ms |
19336 KB |
Output is correct |
96 |
Correct |
58 ms |
17744 KB |
Output is correct |
97 |
Correct |
53 ms |
16196 KB |
Output is correct |
98 |
Correct |
70 ms |
15828 KB |
Output is correct |
99 |
Correct |
59 ms |
15452 KB |
Output is correct |
100 |
Correct |
61 ms |
18524 KB |
Output is correct |
101 |
Correct |
59 ms |
16716 KB |
Output is correct |
102 |
Correct |
69 ms |
15716 KB |
Output is correct |
103 |
Correct |
87 ms |
15768 KB |
Output is correct |
104 |
Correct |
51 ms |
15868 KB |
Output is correct |
105 |
Correct |
73 ms |
24552 KB |
Output is correct |
106 |
Correct |
42 ms |
15556 KB |
Output is correct |
107 |
Correct |
47 ms |
15724 KB |
Output is correct |
108 |
Correct |
76 ms |
28572 KB |
Output is correct |
109 |
Correct |
41 ms |
15972 KB |
Output is correct |
110 |
Correct |
73 ms |
28692 KB |
Output is correct |
111 |
Correct |
66 ms |
14860 KB |
Output is correct |