#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define mp make_pair
#define xx first
#define yy second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(x) x.begin(),x.end()
#define ff(i,a,b) for (int i = a; i < b; i++)
#define fff(i,a,b) for (int i = a; i <= b; i++)
#define bff(i,a,b) for (int i = b-1; i >= a; i--)
#define bfff(i,a,b) for (int i = b; i >= a; i--)
using namespace std;
long double typedef ld;
unsigned int typedef ui;
long long int typedef li;
pair<int,int> typedef pii;
pair<li,li> typedef pli;
pair<ld,ld> typedef pld;
vector<vector<int>> typedef graph;
unsigned long long int typedef ull;
//const int mod = 998244353;
const int mod = 1000000007;
//Note to self: Check for overflow
graph g(200005);
bool struja[200005];
int dp[200005];
int ans=0;
void dfs(int p, int q)
{
int suma=0,mx=0;
for (auto it : g[p]) if (it!=q)
{
dfs(it,p);
suma+=dp[it];
mx=max(mx,dp[it]);
}
ans=max(ans,mx+struja[p]);
dp[p]=max(dp[p],suma-struja[p]);
if (struja[p]) dp[p]=max(dp[p],1);
ans=max(ans,dp[p]);
}
int main()
{
FAST;
int n; cin>>n;
ff(i,1,n)
{
int u,v; cin>>u>>v;
g[u].pb(v),g[v].pb(u);
}
string s; cin>>s;
fff(i,1,n) struja[i]=(s[i-1]=='1');
dfs(1,0);
cout<<ans<<"\n";
//fff(i,1,n) cout<<i<<": "<<dp[i]<<endl;
}
//Note to self: Check for overflow
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
3 ms |
5032 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5040 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
5032 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 |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
5036 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
5028 KB |
Output is correct |
16 |
Correct |
4 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
5044 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
5036 KB |
Output is correct |
20 |
Correct |
3 ms |
5076 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
3 ms |
5032 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5040 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
5032 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 |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
5036 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
5028 KB |
Output is correct |
16 |
Correct |
4 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
5044 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
5036 KB |
Output is correct |
20 |
Correct |
3 ms |
5076 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
4 ms |
5044 KB |
Output is correct |
23 |
Correct |
4 ms |
5204 KB |
Output is correct |
24 |
Correct |
4 ms |
5044 KB |
Output is correct |
25 |
Correct |
4 ms |
5076 KB |
Output is correct |
26 |
Correct |
3 ms |
5076 KB |
Output is correct |
27 |
Correct |
4 ms |
5076 KB |
Output is correct |
28 |
Correct |
4 ms |
5076 KB |
Output is correct |
29 |
Correct |
4 ms |
5248 KB |
Output is correct |
30 |
Correct |
3 ms |
5204 KB |
Output is correct |
31 |
Correct |
5 ms |
5092 KB |
Output is correct |
32 |
Correct |
3 ms |
5076 KB |
Output is correct |
33 |
Correct |
4 ms |
5076 KB |
Output is correct |
34 |
Correct |
4 ms |
5076 KB |
Output is correct |
35 |
Correct |
4 ms |
5076 KB |
Output is correct |
36 |
Correct |
3 ms |
5076 KB |
Output is correct |
37 |
Correct |
3 ms |
5076 KB |
Output is correct |
38 |
Correct |
4 ms |
5076 KB |
Output is correct |
39 |
Correct |
3 ms |
5184 KB |
Output is correct |
40 |
Correct |
4 ms |
5076 KB |
Output is correct |
41 |
Correct |
4 ms |
5180 KB |
Output is correct |
42 |
Correct |
4 ms |
5072 KB |
Output is correct |
43 |
Correct |
4 ms |
5076 KB |
Output is correct |
44 |
Correct |
4 ms |
5076 KB |
Output is correct |
45 |
Correct |
4 ms |
5076 KB |
Output is correct |
46 |
Correct |
3 ms |
5076 KB |
Output is correct |
47 |
Correct |
4 ms |
5076 KB |
Output is correct |
48 |
Correct |
3 ms |
5204 KB |
Output is correct |
49 |
Correct |
4 ms |
5204 KB |
Output is correct |
50 |
Correct |
3 ms |
5076 KB |
Output is correct |
51 |
Correct |
3 ms |
5172 KB |
Output is correct |
52 |
Correct |
3 ms |
5052 KB |
Output is correct |
53 |
Correct |
3 ms |
5044 KB |
Output is correct |
54 |
Correct |
4 ms |
5076 KB |
Output is correct |
55 |
Correct |
4 ms |
5048 KB |
Output is correct |
56 |
Correct |
3 ms |
5076 KB |
Output is correct |
57 |
Correct |
3 ms |
5204 KB |
Output is correct |
58 |
Correct |
3 ms |
5048 KB |
Output is correct |
59 |
Correct |
3 ms |
5076 KB |
Output is correct |
60 |
Correct |
4 ms |
5176 KB |
Output is correct |
61 |
Correct |
4 ms |
5076 KB |
Output is correct |
62 |
Correct |
4 ms |
5204 KB |
Output is correct |
63 |
Correct |
4 ms |
5076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
3 ms |
5032 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5040 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
5032 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 |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
5036 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
5028 KB |
Output is correct |
16 |
Correct |
4 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
5044 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
5036 KB |
Output is correct |
20 |
Correct |
3 ms |
5076 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
4 ms |
5044 KB |
Output is correct |
23 |
Correct |
4 ms |
5204 KB |
Output is correct |
24 |
Correct |
4 ms |
5044 KB |
Output is correct |
25 |
Correct |
4 ms |
5076 KB |
Output is correct |
26 |
Correct |
3 ms |
5076 KB |
Output is correct |
27 |
Correct |
4 ms |
5076 KB |
Output is correct |
28 |
Correct |
4 ms |
5076 KB |
Output is correct |
29 |
Correct |
4 ms |
5248 KB |
Output is correct |
30 |
Correct |
3 ms |
5204 KB |
Output is correct |
31 |
Correct |
5 ms |
5092 KB |
Output is correct |
32 |
Correct |
3 ms |
5076 KB |
Output is correct |
33 |
Correct |
4 ms |
5076 KB |
Output is correct |
34 |
Correct |
4 ms |
5076 KB |
Output is correct |
35 |
Correct |
4 ms |
5076 KB |
Output is correct |
36 |
Correct |
3 ms |
5076 KB |
Output is correct |
37 |
Correct |
3 ms |
5076 KB |
Output is correct |
38 |
Correct |
4 ms |
5076 KB |
Output is correct |
39 |
Correct |
3 ms |
5184 KB |
Output is correct |
40 |
Correct |
4 ms |
5076 KB |
Output is correct |
41 |
Correct |
4 ms |
5180 KB |
Output is correct |
42 |
Correct |
4 ms |
5072 KB |
Output is correct |
43 |
Correct |
4 ms |
5076 KB |
Output is correct |
44 |
Correct |
4 ms |
5076 KB |
Output is correct |
45 |
Correct |
4 ms |
5076 KB |
Output is correct |
46 |
Correct |
3 ms |
5076 KB |
Output is correct |
47 |
Correct |
4 ms |
5076 KB |
Output is correct |
48 |
Correct |
3 ms |
5204 KB |
Output is correct |
49 |
Correct |
4 ms |
5204 KB |
Output is correct |
50 |
Correct |
3 ms |
5076 KB |
Output is correct |
51 |
Correct |
3 ms |
5172 KB |
Output is correct |
52 |
Correct |
3 ms |
5052 KB |
Output is correct |
53 |
Correct |
3 ms |
5044 KB |
Output is correct |
54 |
Correct |
4 ms |
5076 KB |
Output is correct |
55 |
Correct |
4 ms |
5048 KB |
Output is correct |
56 |
Correct |
3 ms |
5076 KB |
Output is correct |
57 |
Correct |
3 ms |
5204 KB |
Output is correct |
58 |
Correct |
3 ms |
5048 KB |
Output is correct |
59 |
Correct |
3 ms |
5076 KB |
Output is correct |
60 |
Correct |
4 ms |
5176 KB |
Output is correct |
61 |
Correct |
4 ms |
5076 KB |
Output is correct |
62 |
Correct |
4 ms |
5204 KB |
Output is correct |
63 |
Correct |
4 ms |
5076 KB |
Output is correct |
64 |
Correct |
115 ms |
15356 KB |
Output is correct |
65 |
Correct |
132 ms |
15320 KB |
Output is correct |
66 |
Correct |
126 ms |
15288 KB |
Output is correct |
67 |
Correct |
117 ms |
15412 KB |
Output is correct |
68 |
Correct |
120 ms |
15352 KB |
Output is correct |
69 |
Correct |
146 ms |
15332 KB |
Output is correct |
70 |
Correct |
116 ms |
15420 KB |
Output is correct |
71 |
Correct |
137 ms |
15352 KB |
Output is correct |
72 |
Correct |
138 ms |
15400 KB |
Output is correct |
73 |
Correct |
148 ms |
30480 KB |
Output is correct |
74 |
Correct |
130 ms |
30480 KB |
Output is correct |
75 |
Correct |
140 ms |
15188 KB |
Output is correct |
76 |
Correct |
118 ms |
15292 KB |
Output is correct |
77 |
Correct |
114 ms |
15296 KB |
Output is correct |
78 |
Correct |
120 ms |
15288 KB |
Output is correct |
79 |
Correct |
120 ms |
15188 KB |
Output is correct |
80 |
Correct |
135 ms |
15236 KB |
Output is correct |
81 |
Correct |
97 ms |
15688 KB |
Output is correct |
82 |
Correct |
117 ms |
15456 KB |
Output is correct |
83 |
Correct |
141 ms |
21444 KB |
Output is correct |
84 |
Correct |
139 ms |
24088 KB |
Output is correct |
85 |
Correct |
133 ms |
23676 KB |
Output is correct |
86 |
Correct |
142 ms |
17000 KB |
Output is correct |
87 |
Correct |
131 ms |
16320 KB |
Output is correct |
88 |
Correct |
112 ms |
16740 KB |
Output is correct |
89 |
Correct |
111 ms |
16776 KB |
Output is correct |
90 |
Correct |
145 ms |
16516 KB |
Output is correct |
91 |
Correct |
107 ms |
16748 KB |
Output is correct |
92 |
Correct |
128 ms |
17080 KB |
Output is correct |
93 |
Correct |
102 ms |
20096 KB |
Output is correct |
94 |
Correct |
119 ms |
22212 KB |
Output is correct |
95 |
Correct |
110 ms |
20520 KB |
Output is correct |
96 |
Correct |
103 ms |
18488 KB |
Output is correct |
97 |
Correct |
117 ms |
16484 KB |
Output is correct |
98 |
Correct |
127 ms |
15932 KB |
Output is correct |
99 |
Correct |
136 ms |
15672 KB |
Output is correct |
100 |
Correct |
108 ms |
19492 KB |
Output is correct |
101 |
Correct |
119 ms |
17132 KB |
Output is correct |
102 |
Correct |
120 ms |
16112 KB |
Output is correct |
103 |
Correct |
121 ms |
15952 KB |
Output is correct |
104 |
Correct |
62 ms |
16188 KB |
Output is correct |
105 |
Correct |
131 ms |
26720 KB |
Output is correct |
106 |
Correct |
68 ms |
16084 KB |
Output is correct |
107 |
Correct |
89 ms |
16064 KB |
Output is correct |
108 |
Correct |
152 ms |
31424 KB |
Output is correct |
109 |
Correct |
68 ms |
16292 KB |
Output is correct |
110 |
Correct |
139 ms |
31764 KB |
Output is correct |
111 |
Correct |
150 ms |
15260 KB |
Output is correct |