//Be Name Khoda
#include<bits/stdc++.h>
//pragma shayad niaz she
using namespace std;
typedef long long ll;
typedef long double ld;
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
const ll mxn = 2e5 + 16;
ll n, m, t, q, w, ans;
ll dp[mxn], subt[mxn];
vector<ll> adj[mxn];
bool mark[mxn];
string s;
void input() {
cin >> n;
for(int i = 1; i < n; i++) {
cin >> q >> w;
adj[q].push_back(w);
adj[w].push_back(q);
} cin >> s;
s = '0' + s;
}
void DFS(int v) {
mark[v] = 1;
ll cnt = 0, sum = 0, idk = 0;
if(s[v] == '1') dp[v] = 1, subt[v] = 1;
for(auto u : adj[v]) {
if(!mark[u]) {
DFS(u);
if(subt[u] > 0) {
subt[v] += subt[u];
cnt++, sum += dp[u];
idk = max(idk, dp[u]);
}
}
}
if(s[v] == '1') {
ans = max(ans, idk + 1);
sum--;
}
dp[v] = max(dp[v], sum);
return;
}
void solve() {
ll cnt = 0;
for(auto u : s) {
if(u == '1') cnt++;
}
DFS(1);
for(int i = 1; i <= n; i++) {
ans = max(ans, dp[i]);
}
cout << ans << "\n";
return;
}
int main() {
ios::sync_with_stdio(false); cin.tie(NULL);
input(), solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
5016 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 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 |
2 ms |
4948 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 |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
5036 KB |
Output is correct |
17 |
Correct |
3 ms |
5028 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
5028 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
5036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
5016 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 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 |
2 ms |
4948 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 |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
5036 KB |
Output is correct |
17 |
Correct |
3 ms |
5028 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
5028 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
5036 KB |
Output is correct |
22 |
Correct |
4 ms |
5076 KB |
Output is correct |
23 |
Correct |
5 ms |
5096 KB |
Output is correct |
24 |
Correct |
3 ms |
5096 KB |
Output is correct |
25 |
Correct |
4 ms |
5076 KB |
Output is correct |
26 |
Correct |
4 ms |
5076 KB |
Output is correct |
27 |
Correct |
3 ms |
5044 KB |
Output is correct |
28 |
Correct |
5 ms |
5076 KB |
Output is correct |
29 |
Correct |
5 ms |
5204 KB |
Output is correct |
30 |
Correct |
3 ms |
5204 KB |
Output is correct |
31 |
Correct |
7 ms |
5104 KB |
Output is correct |
32 |
Correct |
4 ms |
5172 KB |
Output is correct |
33 |
Correct |
3 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 |
5092 KB |
Output is correct |
37 |
Correct |
4 ms |
5076 KB |
Output is correct |
38 |
Correct |
4 ms |
5076 KB |
Output is correct |
39 |
Correct |
3 ms |
5172 KB |
Output is correct |
40 |
Correct |
3 ms |
5076 KB |
Output is correct |
41 |
Correct |
3 ms |
5204 KB |
Output is correct |
42 |
Correct |
4 ms |
5076 KB |
Output is correct |
43 |
Correct |
4 ms |
5100 KB |
Output is correct |
44 |
Correct |
4 ms |
5076 KB |
Output is correct |
45 |
Correct |
3 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 |
3 ms |
5172 KB |
Output is correct |
50 |
Correct |
3 ms |
5172 KB |
Output is correct |
51 |
Correct |
3 ms |
5204 KB |
Output is correct |
52 |
Correct |
3 ms |
5092 KB |
Output is correct |
53 |
Correct |
4 ms |
5076 KB |
Output is correct |
54 |
Correct |
4 ms |
5076 KB |
Output is correct |
55 |
Correct |
4 ms |
5076 KB |
Output is correct |
56 |
Correct |
3 ms |
5076 KB |
Output is correct |
57 |
Correct |
4 ms |
5204 KB |
Output is correct |
58 |
Correct |
4 ms |
5176 KB |
Output is correct |
59 |
Correct |
5 ms |
5080 KB |
Output is correct |
60 |
Correct |
5 ms |
5204 KB |
Output is correct |
61 |
Correct |
3 ms |
5092 KB |
Output is correct |
62 |
Correct |
4 ms |
5204 KB |
Output is correct |
63 |
Correct |
3 ms |
5076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
5016 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 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 |
2 ms |
4948 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 |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
5036 KB |
Output is correct |
17 |
Correct |
3 ms |
5028 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
5028 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
5036 KB |
Output is correct |
22 |
Correct |
4 ms |
5076 KB |
Output is correct |
23 |
Correct |
5 ms |
5096 KB |
Output is correct |
24 |
Correct |
3 ms |
5096 KB |
Output is correct |
25 |
Correct |
4 ms |
5076 KB |
Output is correct |
26 |
Correct |
4 ms |
5076 KB |
Output is correct |
27 |
Correct |
3 ms |
5044 KB |
Output is correct |
28 |
Correct |
5 ms |
5076 KB |
Output is correct |
29 |
Correct |
5 ms |
5204 KB |
Output is correct |
30 |
Correct |
3 ms |
5204 KB |
Output is correct |
31 |
Correct |
7 ms |
5104 KB |
Output is correct |
32 |
Correct |
4 ms |
5172 KB |
Output is correct |
33 |
Correct |
3 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 |
5092 KB |
Output is correct |
37 |
Correct |
4 ms |
5076 KB |
Output is correct |
38 |
Correct |
4 ms |
5076 KB |
Output is correct |
39 |
Correct |
3 ms |
5172 KB |
Output is correct |
40 |
Correct |
3 ms |
5076 KB |
Output is correct |
41 |
Correct |
3 ms |
5204 KB |
Output is correct |
42 |
Correct |
4 ms |
5076 KB |
Output is correct |
43 |
Correct |
4 ms |
5100 KB |
Output is correct |
44 |
Correct |
4 ms |
5076 KB |
Output is correct |
45 |
Correct |
3 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 |
3 ms |
5172 KB |
Output is correct |
50 |
Correct |
3 ms |
5172 KB |
Output is correct |
51 |
Correct |
3 ms |
5204 KB |
Output is correct |
52 |
Correct |
3 ms |
5092 KB |
Output is correct |
53 |
Correct |
4 ms |
5076 KB |
Output is correct |
54 |
Correct |
4 ms |
5076 KB |
Output is correct |
55 |
Correct |
4 ms |
5076 KB |
Output is correct |
56 |
Correct |
3 ms |
5076 KB |
Output is correct |
57 |
Correct |
4 ms |
5204 KB |
Output is correct |
58 |
Correct |
4 ms |
5176 KB |
Output is correct |
59 |
Correct |
5 ms |
5080 KB |
Output is correct |
60 |
Correct |
5 ms |
5204 KB |
Output is correct |
61 |
Correct |
3 ms |
5092 KB |
Output is correct |
62 |
Correct |
4 ms |
5204 KB |
Output is correct |
63 |
Correct |
3 ms |
5076 KB |
Output is correct |
64 |
Correct |
148 ms |
18652 KB |
Output is correct |
65 |
Correct |
133 ms |
18656 KB |
Output is correct |
66 |
Correct |
129 ms |
18620 KB |
Output is correct |
67 |
Correct |
119 ms |
18660 KB |
Output is correct |
68 |
Correct |
124 ms |
18608 KB |
Output is correct |
69 |
Correct |
132 ms |
18640 KB |
Output is correct |
70 |
Correct |
138 ms |
18672 KB |
Output is correct |
71 |
Correct |
140 ms |
18660 KB |
Output is correct |
72 |
Correct |
123 ms |
17736 KB |
Output is correct |
73 |
Correct |
162 ms |
30332 KB |
Output is correct |
74 |
Correct |
147 ms |
30280 KB |
Output is correct |
75 |
Correct |
148 ms |
19928 KB |
Output is correct |
76 |
Correct |
158 ms |
19948 KB |
Output is correct |
77 |
Correct |
140 ms |
18744 KB |
Output is correct |
78 |
Correct |
144 ms |
18628 KB |
Output is correct |
79 |
Correct |
120 ms |
18636 KB |
Output is correct |
80 |
Correct |
131 ms |
18668 KB |
Output is correct |
81 |
Correct |
114 ms |
18684 KB |
Output is correct |
82 |
Correct |
153 ms |
18504 KB |
Output is correct |
83 |
Correct |
134 ms |
23704 KB |
Output is correct |
84 |
Correct |
166 ms |
25940 KB |
Output is correct |
85 |
Correct |
174 ms |
25580 KB |
Output is correct |
86 |
Correct |
131 ms |
20040 KB |
Output is correct |
87 |
Correct |
138 ms |
19396 KB |
Output is correct |
88 |
Correct |
160 ms |
19516 KB |
Output is correct |
89 |
Correct |
133 ms |
19664 KB |
Output is correct |
90 |
Correct |
112 ms |
19312 KB |
Output is correct |
91 |
Correct |
133 ms |
19544 KB |
Output is correct |
92 |
Correct |
121 ms |
19908 KB |
Output is correct |
93 |
Correct |
129 ms |
22172 KB |
Output is correct |
94 |
Correct |
120 ms |
23752 KB |
Output is correct |
95 |
Correct |
120 ms |
22372 KB |
Output is correct |
96 |
Correct |
157 ms |
20664 KB |
Output is correct |
97 |
Correct |
132 ms |
19224 KB |
Output is correct |
98 |
Correct |
125 ms |
18804 KB |
Output is correct |
99 |
Correct |
119 ms |
18736 KB |
Output is correct |
100 |
Correct |
116 ms |
21744 KB |
Output is correct |
101 |
Correct |
126 ms |
19568 KB |
Output is correct |
102 |
Correct |
141 ms |
18972 KB |
Output is correct |
103 |
Correct |
133 ms |
18984 KB |
Output is correct |
104 |
Correct |
81 ms |
17852 KB |
Output is correct |
105 |
Correct |
143 ms |
27112 KB |
Output is correct |
106 |
Correct |
74 ms |
19188 KB |
Output is correct |
107 |
Correct |
80 ms |
19192 KB |
Output is correct |
108 |
Correct |
140 ms |
31060 KB |
Output is correct |
109 |
Correct |
66 ms |
17856 KB |
Output is correct |
110 |
Correct |
135 ms |
31376 KB |
Output is correct |
111 |
Correct |
114 ms |
18620 KB |
Output is correct |