#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define sumof(x) accumulate(all(x), 0ll)
const int N=2e5+1;
int n, a[N], f[N][2];
vector<int> g[N];
void dfs(int u, int p){
for (int v:g[u]) if (v!=p) dfs(v, u);
int m=0;
for (int v:g[u]) if (v!=p){
f[u][0]+=f[v][1];
m=max(m, f[v][1]);
}
int x=f[u][0]-a[u];
f[u][0]=max(x, a[u]+m);
f[u][1]=max(x, a[u]);
}
void solve(int tc){
// cout << "Case #" << tc << ": ";
cin >> n;
for (int i=1; i<n; ++i){
int x, y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
for (int i=1; i<=n; ++i){
char c; cin >> c;
a[i]=c-'0';
}
dfs(1, 1);
int ans=0;
for (int i=1; i<=n; ++i) ans=max(ans, f[i][0]);
cout << ans;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int ntests=1;
// cin >> ntests;
for (int i=1; i<=ntests; ++i) solve(i);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
5028 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5032 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
5000 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
2 ms |
5028 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
5032 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
4 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
2 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
5028 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5032 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
5000 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
2 ms |
5028 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
5032 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
4 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
2 ms |
4948 KB |
Output is correct |
22 |
Correct |
4 ms |
5076 KB |
Output is correct |
23 |
Correct |
3 ms |
5076 KB |
Output is correct |
24 |
Correct |
5 ms |
5164 KB |
Output is correct |
25 |
Correct |
3 ms |
5076 KB |
Output is correct |
26 |
Correct |
3 ms |
5076 KB |
Output is correct |
27 |
Correct |
4 ms |
5092 KB |
Output is correct |
28 |
Correct |
3 ms |
5164 KB |
Output is correct |
29 |
Correct |
3 ms |
5168 KB |
Output is correct |
30 |
Correct |
3 ms |
5204 KB |
Output is correct |
31 |
Correct |
3 ms |
5076 KB |
Output is correct |
32 |
Correct |
3 ms |
5076 KB |
Output is correct |
33 |
Correct |
4 ms |
5076 KB |
Output is correct |
34 |
Correct |
3 ms |
5076 KB |
Output is correct |
35 |
Correct |
3 ms |
5076 KB |
Output is correct |
36 |
Correct |
4 ms |
5172 KB |
Output is correct |
37 |
Correct |
4 ms |
5168 KB |
Output is correct |
38 |
Correct |
3 ms |
5076 KB |
Output is correct |
39 |
Correct |
4 ms |
5204 KB |
Output is correct |
40 |
Correct |
4 ms |
5076 KB |
Output is correct |
41 |
Correct |
3 ms |
5164 KB |
Output is correct |
42 |
Correct |
3 ms |
5076 KB |
Output is correct |
43 |
Correct |
3 ms |
5076 KB |
Output is correct |
44 |
Correct |
3 ms |
5172 KB |
Output is correct |
45 |
Correct |
4 ms |
5088 KB |
Output is correct |
46 |
Correct |
3 ms |
5164 KB |
Output is correct |
47 |
Correct |
4 ms |
5076 KB |
Output is correct |
48 |
Correct |
3 ms |
5204 KB |
Output is correct |
49 |
Correct |
3 ms |
5204 KB |
Output is correct |
50 |
Correct |
3 ms |
5076 KB |
Output is correct |
51 |
Correct |
3 ms |
5204 KB |
Output is correct |
52 |
Correct |
3 ms |
5076 KB |
Output is correct |
53 |
Correct |
3 ms |
5164 KB |
Output is correct |
54 |
Correct |
3 ms |
5076 KB |
Output is correct |
55 |
Correct |
3 ms |
5076 KB |
Output is correct |
56 |
Correct |
3 ms |
5076 KB |
Output is correct |
57 |
Correct |
3 ms |
5168 KB |
Output is correct |
58 |
Correct |
3 ms |
5076 KB |
Output is correct |
59 |
Correct |
3 ms |
5168 KB |
Output is correct |
60 |
Correct |
3 ms |
5172 KB |
Output is correct |
61 |
Correct |
3 ms |
5076 KB |
Output is correct |
62 |
Correct |
3 ms |
5168 KB |
Output is correct |
63 |
Correct |
3 ms |
5164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
5028 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5032 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
5000 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
2 ms |
5028 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
5032 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
4 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
2 ms |
4948 KB |
Output is correct |
22 |
Correct |
4 ms |
5076 KB |
Output is correct |
23 |
Correct |
3 ms |
5076 KB |
Output is correct |
24 |
Correct |
5 ms |
5164 KB |
Output is correct |
25 |
Correct |
3 ms |
5076 KB |
Output is correct |
26 |
Correct |
3 ms |
5076 KB |
Output is correct |
27 |
Correct |
4 ms |
5092 KB |
Output is correct |
28 |
Correct |
3 ms |
5164 KB |
Output is correct |
29 |
Correct |
3 ms |
5168 KB |
Output is correct |
30 |
Correct |
3 ms |
5204 KB |
Output is correct |
31 |
Correct |
3 ms |
5076 KB |
Output is correct |
32 |
Correct |
3 ms |
5076 KB |
Output is correct |
33 |
Correct |
4 ms |
5076 KB |
Output is correct |
34 |
Correct |
3 ms |
5076 KB |
Output is correct |
35 |
Correct |
3 ms |
5076 KB |
Output is correct |
36 |
Correct |
4 ms |
5172 KB |
Output is correct |
37 |
Correct |
4 ms |
5168 KB |
Output is correct |
38 |
Correct |
3 ms |
5076 KB |
Output is correct |
39 |
Correct |
4 ms |
5204 KB |
Output is correct |
40 |
Correct |
4 ms |
5076 KB |
Output is correct |
41 |
Correct |
3 ms |
5164 KB |
Output is correct |
42 |
Correct |
3 ms |
5076 KB |
Output is correct |
43 |
Correct |
3 ms |
5076 KB |
Output is correct |
44 |
Correct |
3 ms |
5172 KB |
Output is correct |
45 |
Correct |
4 ms |
5088 KB |
Output is correct |
46 |
Correct |
3 ms |
5164 KB |
Output is correct |
47 |
Correct |
4 ms |
5076 KB |
Output is correct |
48 |
Correct |
3 ms |
5204 KB |
Output is correct |
49 |
Correct |
3 ms |
5204 KB |
Output is correct |
50 |
Correct |
3 ms |
5076 KB |
Output is correct |
51 |
Correct |
3 ms |
5204 KB |
Output is correct |
52 |
Correct |
3 ms |
5076 KB |
Output is correct |
53 |
Correct |
3 ms |
5164 KB |
Output is correct |
54 |
Correct |
3 ms |
5076 KB |
Output is correct |
55 |
Correct |
3 ms |
5076 KB |
Output is correct |
56 |
Correct |
3 ms |
5076 KB |
Output is correct |
57 |
Correct |
3 ms |
5168 KB |
Output is correct |
58 |
Correct |
3 ms |
5076 KB |
Output is correct |
59 |
Correct |
3 ms |
5168 KB |
Output is correct |
60 |
Correct |
3 ms |
5172 KB |
Output is correct |
61 |
Correct |
3 ms |
5076 KB |
Output is correct |
62 |
Correct |
3 ms |
5168 KB |
Output is correct |
63 |
Correct |
3 ms |
5164 KB |
Output is correct |
64 |
Correct |
82 ms |
17188 KB |
Output is correct |
65 |
Correct |
86 ms |
17292 KB |
Output is correct |
66 |
Correct |
87 ms |
17184 KB |
Output is correct |
67 |
Correct |
92 ms |
17288 KB |
Output is correct |
68 |
Correct |
87 ms |
17236 KB |
Output is correct |
69 |
Correct |
94 ms |
17296 KB |
Output is correct |
70 |
Correct |
90 ms |
17248 KB |
Output is correct |
71 |
Correct |
88 ms |
17240 KB |
Output is correct |
72 |
Correct |
92 ms |
17208 KB |
Output is correct |
73 |
Correct |
117 ms |
23892 KB |
Output is correct |
74 |
Correct |
146 ms |
23804 KB |
Output is correct |
75 |
Correct |
88 ms |
18524 KB |
Output is correct |
76 |
Correct |
90 ms |
18508 KB |
Output is correct |
77 |
Correct |
89 ms |
17260 KB |
Output is correct |
78 |
Correct |
98 ms |
17268 KB |
Output is correct |
79 |
Correct |
98 ms |
17200 KB |
Output is correct |
80 |
Correct |
86 ms |
17244 KB |
Output is correct |
81 |
Correct |
70 ms |
17220 KB |
Output is correct |
82 |
Correct |
80 ms |
17152 KB |
Output is correct |
83 |
Correct |
120 ms |
20288 KB |
Output is correct |
84 |
Correct |
108 ms |
21584 KB |
Output is correct |
85 |
Correct |
94 ms |
21296 KB |
Output is correct |
86 |
Correct |
93 ms |
18104 KB |
Output is correct |
87 |
Correct |
99 ms |
17704 KB |
Output is correct |
88 |
Correct |
101 ms |
17828 KB |
Output is correct |
89 |
Correct |
98 ms |
17816 KB |
Output is correct |
90 |
Correct |
82 ms |
17800 KB |
Output is correct |
91 |
Correct |
96 ms |
18016 KB |
Output is correct |
92 |
Correct |
98 ms |
18108 KB |
Output is correct |
93 |
Correct |
82 ms |
19264 KB |
Output is correct |
94 |
Correct |
77 ms |
20176 KB |
Output is correct |
95 |
Correct |
78 ms |
19364 KB |
Output is correct |
96 |
Correct |
81 ms |
18384 KB |
Output is correct |
97 |
Correct |
91 ms |
17588 KB |
Output is correct |
98 |
Correct |
77 ms |
17420 KB |
Output is correct |
99 |
Correct |
115 ms |
17332 KB |
Output is correct |
100 |
Correct |
91 ms |
19048 KB |
Output is correct |
101 |
Correct |
109 ms |
17760 KB |
Output is correct |
102 |
Correct |
103 ms |
17408 KB |
Output is correct |
103 |
Correct |
83 ms |
17548 KB |
Output is correct |
104 |
Correct |
67 ms |
17740 KB |
Output is correct |
105 |
Correct |
99 ms |
21816 KB |
Output is correct |
106 |
Correct |
54 ms |
17676 KB |
Output is correct |
107 |
Correct |
54 ms |
17712 KB |
Output is correct |
108 |
Correct |
116 ms |
24232 KB |
Output is correct |
109 |
Correct |
72 ms |
17788 KB |
Output is correct |
110 |
Correct |
98 ms |
24496 KB |
Output is correct |
111 |
Correct |
77 ms |
17212 KB |
Output is correct |