#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int n;
str s;
vector <vector<int>> v;
ll ans = 0;
int snd;
ll dfs(int nd, int ss){
ll r = '0'-s[nd];
if(ss == -1 && v[nd].size() == 1) r = 1;
for(int x: v[nd]) if(x != ss) r+=dfs(x, nd);
//cout << nd << " " << r << " " << s[nd] - '0' << " de\n";
return max(r, (ll)s[nd] - '0');
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
v = vector<vector<int>> (n+1);
for(int i = 1; i < n; i++){
int a, b; cin >> a >> b;
v[a].pb(b);
v[b].pb(a);
}
cin >> s;
s = "x"+s;
for(int i = 1; i <= n; i++) if(s[i] == '1') ans = max(ans, dfs(i, -1));
//cout << dfs(2, -1) << "\n";
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
67 ms |
512 KB |
Output is correct |
23 |
Correct |
61 ms |
512 KB |
Output is correct |
24 |
Correct |
53 ms |
512 KB |
Output is correct |
25 |
Correct |
35 ms |
512 KB |
Output is correct |
26 |
Correct |
18 ms |
512 KB |
Output is correct |
27 |
Correct |
8 ms |
640 KB |
Output is correct |
28 |
Correct |
1 ms |
512 KB |
Output is correct |
29 |
Correct |
86 ms |
632 KB |
Output is correct |
30 |
Correct |
45 ms |
636 KB |
Output is correct |
31 |
Correct |
59 ms |
512 KB |
Output is correct |
32 |
Correct |
31 ms |
512 KB |
Output is correct |
33 |
Correct |
62 ms |
512 KB |
Output is correct |
34 |
Correct |
36 ms |
516 KB |
Output is correct |
35 |
Correct |
18 ms |
512 KB |
Output is correct |
36 |
Correct |
8 ms |
512 KB |
Output is correct |
37 |
Correct |
42 ms |
512 KB |
Output is correct |
38 |
Correct |
30 ms |
512 KB |
Output is correct |
39 |
Correct |
79 ms |
512 KB |
Output is correct |
40 |
Correct |
40 ms |
512 KB |
Output is correct |
41 |
Correct |
22 ms |
640 KB |
Output is correct |
42 |
Correct |
37 ms |
512 KB |
Output is correct |
43 |
Correct |
9 ms |
512 KB |
Output is correct |
44 |
Correct |
58 ms |
552 KB |
Output is correct |
45 |
Correct |
47 ms |
512 KB |
Output is correct |
46 |
Correct |
31 ms |
512 KB |
Output is correct |
47 |
Correct |
16 ms |
512 KB |
Output is correct |
48 |
Correct |
56 ms |
512 KB |
Output is correct |
49 |
Correct |
60 ms |
512 KB |
Output is correct |
50 |
Correct |
58 ms |
564 KB |
Output is correct |
51 |
Correct |
59 ms |
512 KB |
Output is correct |
52 |
Correct |
62 ms |
528 KB |
Output is correct |
53 |
Correct |
45 ms |
632 KB |
Output is correct |
54 |
Correct |
58 ms |
512 KB |
Output is correct |
55 |
Correct |
62 ms |
632 KB |
Output is correct |
56 |
Correct |
1 ms |
512 KB |
Output is correct |
57 |
Correct |
1 ms |
640 KB |
Output is correct |
58 |
Correct |
27 ms |
512 KB |
Output is correct |
59 |
Correct |
31 ms |
512 KB |
Output is correct |
60 |
Correct |
2 ms |
640 KB |
Output is correct |
61 |
Correct |
1 ms |
512 KB |
Output is correct |
62 |
Correct |
2 ms |
640 KB |
Output is correct |
63 |
Correct |
51 ms |
408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
67 ms |
512 KB |
Output is correct |
23 |
Correct |
61 ms |
512 KB |
Output is correct |
24 |
Correct |
53 ms |
512 KB |
Output is correct |
25 |
Correct |
35 ms |
512 KB |
Output is correct |
26 |
Correct |
18 ms |
512 KB |
Output is correct |
27 |
Correct |
8 ms |
640 KB |
Output is correct |
28 |
Correct |
1 ms |
512 KB |
Output is correct |
29 |
Correct |
86 ms |
632 KB |
Output is correct |
30 |
Correct |
45 ms |
636 KB |
Output is correct |
31 |
Correct |
59 ms |
512 KB |
Output is correct |
32 |
Correct |
31 ms |
512 KB |
Output is correct |
33 |
Correct |
62 ms |
512 KB |
Output is correct |
34 |
Correct |
36 ms |
516 KB |
Output is correct |
35 |
Correct |
18 ms |
512 KB |
Output is correct |
36 |
Correct |
8 ms |
512 KB |
Output is correct |
37 |
Correct |
42 ms |
512 KB |
Output is correct |
38 |
Correct |
30 ms |
512 KB |
Output is correct |
39 |
Correct |
79 ms |
512 KB |
Output is correct |
40 |
Correct |
40 ms |
512 KB |
Output is correct |
41 |
Correct |
22 ms |
640 KB |
Output is correct |
42 |
Correct |
37 ms |
512 KB |
Output is correct |
43 |
Correct |
9 ms |
512 KB |
Output is correct |
44 |
Correct |
58 ms |
552 KB |
Output is correct |
45 |
Correct |
47 ms |
512 KB |
Output is correct |
46 |
Correct |
31 ms |
512 KB |
Output is correct |
47 |
Correct |
16 ms |
512 KB |
Output is correct |
48 |
Correct |
56 ms |
512 KB |
Output is correct |
49 |
Correct |
60 ms |
512 KB |
Output is correct |
50 |
Correct |
58 ms |
564 KB |
Output is correct |
51 |
Correct |
59 ms |
512 KB |
Output is correct |
52 |
Correct |
62 ms |
528 KB |
Output is correct |
53 |
Correct |
45 ms |
632 KB |
Output is correct |
54 |
Correct |
58 ms |
512 KB |
Output is correct |
55 |
Correct |
62 ms |
632 KB |
Output is correct |
56 |
Correct |
1 ms |
512 KB |
Output is correct |
57 |
Correct |
1 ms |
640 KB |
Output is correct |
58 |
Correct |
27 ms |
512 KB |
Output is correct |
59 |
Correct |
31 ms |
512 KB |
Output is correct |
60 |
Correct |
2 ms |
640 KB |
Output is correct |
61 |
Correct |
1 ms |
512 KB |
Output is correct |
62 |
Correct |
2 ms |
640 KB |
Output is correct |
63 |
Correct |
51 ms |
408 KB |
Output is correct |
64 |
Execution timed out |
1573 ms |
12204 KB |
Time limit exceeded |
65 |
Halted |
0 ms |
0 KB |
- |