#include<bits/stdc++.h>
#define f first
#define int long long
#define s second
using namespace std;
const int N=2e5+5,mod=1e9+7;
int t,ans,dp[N],u,v,n;
string s;
vector<int>V[N];
void dfs(int u,int p){
if(s[u]=='1') dp[u] = 1;
int sum = 0, mx = 0;
for(int i=0;i<V[u].size();i++){
if(V[u][i] == p) continue;
dfs(V[u][i],u);
sum+=dp[V[u][i]];
mx=max(mx,dp[V[u][i]]);
}
ans = max(ans,max(mx+(s[u]=='1'), sum - (s[u]=='1')));
dp[u] = max(dp[u], sum-(s[u]=='1'));
}
main(){
// t=1;
cin>>n;
for(int i=2;i<=n;i++){
cin>>u>>v;
V[u].push_back(v);
V[v].push_back(u);
}
cin>>s;
s='#'+s;
dfs(1,0);
cout<<ans;
}
Compilation message
power.cpp: In function 'void dfs(long long int, long long int)':
power.cpp:13:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | for(int i=0;i<V[u].size();i++){
| ~^~~~~~~~~~~~
power.cpp: At global scope:
power.cpp:22:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
22 | main(){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
3 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4944 KB |
Output is correct |
11 |
Correct |
3 ms |
4940 KB |
Output is correct |
12 |
Correct |
4 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
4940 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
4 ms |
4940 KB |
Output is correct |
20 |
Correct |
3 ms |
4940 KB |
Output is correct |
21 |
Correct |
3 ms |
4940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
3 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4944 KB |
Output is correct |
11 |
Correct |
3 ms |
4940 KB |
Output is correct |
12 |
Correct |
4 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
4940 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
4 ms |
4940 KB |
Output is correct |
20 |
Correct |
3 ms |
4940 KB |
Output is correct |
21 |
Correct |
3 ms |
4940 KB |
Output is correct |
22 |
Correct |
5 ms |
5068 KB |
Output is correct |
23 |
Correct |
4 ms |
5068 KB |
Output is correct |
24 |
Correct |
4 ms |
5044 KB |
Output is correct |
25 |
Correct |
5 ms |
5068 KB |
Output is correct |
26 |
Correct |
5 ms |
5068 KB |
Output is correct |
27 |
Correct |
5 ms |
5068 KB |
Output is correct |
28 |
Correct |
5 ms |
5068 KB |
Output is correct |
29 |
Correct |
5 ms |
5140 KB |
Output is correct |
30 |
Correct |
5 ms |
5068 KB |
Output is correct |
31 |
Correct |
5 ms |
5004 KB |
Output is correct |
32 |
Correct |
5 ms |
5068 KB |
Output is correct |
33 |
Correct |
5 ms |
5068 KB |
Output is correct |
34 |
Correct |
5 ms |
5068 KB |
Output is correct |
35 |
Correct |
5 ms |
5068 KB |
Output is correct |
36 |
Correct |
5 ms |
5072 KB |
Output is correct |
37 |
Correct |
5 ms |
5104 KB |
Output is correct |
38 |
Correct |
5 ms |
5068 KB |
Output is correct |
39 |
Correct |
5 ms |
5068 KB |
Output is correct |
40 |
Correct |
5 ms |
5068 KB |
Output is correct |
41 |
Correct |
5 ms |
5068 KB |
Output is correct |
42 |
Correct |
5 ms |
5068 KB |
Output is correct |
43 |
Correct |
5 ms |
5068 KB |
Output is correct |
44 |
Correct |
4 ms |
5068 KB |
Output is correct |
45 |
Correct |
6 ms |
5068 KB |
Output is correct |
46 |
Correct |
5 ms |
5068 KB |
Output is correct |
47 |
Correct |
5 ms |
5068 KB |
Output is correct |
48 |
Correct |
5 ms |
5068 KB |
Output is correct |
49 |
Correct |
5 ms |
5072 KB |
Output is correct |
50 |
Correct |
4 ms |
5068 KB |
Output is correct |
51 |
Correct |
5 ms |
5068 KB |
Output is correct |
52 |
Correct |
5 ms |
5068 KB |
Output is correct |
53 |
Correct |
5 ms |
5068 KB |
Output is correct |
54 |
Correct |
5 ms |
5068 KB |
Output is correct |
55 |
Correct |
5 ms |
5068 KB |
Output is correct |
56 |
Correct |
5 ms |
5068 KB |
Output is correct |
57 |
Correct |
5 ms |
5196 KB |
Output is correct |
58 |
Correct |
4 ms |
5068 KB |
Output is correct |
59 |
Correct |
5 ms |
5068 KB |
Output is correct |
60 |
Correct |
5 ms |
5068 KB |
Output is correct |
61 |
Correct |
4 ms |
5068 KB |
Output is correct |
62 |
Correct |
4 ms |
5196 KB |
Output is correct |
63 |
Correct |
4 ms |
5068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
3 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4944 KB |
Output is correct |
11 |
Correct |
3 ms |
4940 KB |
Output is correct |
12 |
Correct |
4 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
4940 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
4 ms |
4940 KB |
Output is correct |
20 |
Correct |
3 ms |
4940 KB |
Output is correct |
21 |
Correct |
3 ms |
4940 KB |
Output is correct |
22 |
Correct |
5 ms |
5068 KB |
Output is correct |
23 |
Correct |
4 ms |
5068 KB |
Output is correct |
24 |
Correct |
4 ms |
5044 KB |
Output is correct |
25 |
Correct |
5 ms |
5068 KB |
Output is correct |
26 |
Correct |
5 ms |
5068 KB |
Output is correct |
27 |
Correct |
5 ms |
5068 KB |
Output is correct |
28 |
Correct |
5 ms |
5068 KB |
Output is correct |
29 |
Correct |
5 ms |
5140 KB |
Output is correct |
30 |
Correct |
5 ms |
5068 KB |
Output is correct |
31 |
Correct |
5 ms |
5004 KB |
Output is correct |
32 |
Correct |
5 ms |
5068 KB |
Output is correct |
33 |
Correct |
5 ms |
5068 KB |
Output is correct |
34 |
Correct |
5 ms |
5068 KB |
Output is correct |
35 |
Correct |
5 ms |
5068 KB |
Output is correct |
36 |
Correct |
5 ms |
5072 KB |
Output is correct |
37 |
Correct |
5 ms |
5104 KB |
Output is correct |
38 |
Correct |
5 ms |
5068 KB |
Output is correct |
39 |
Correct |
5 ms |
5068 KB |
Output is correct |
40 |
Correct |
5 ms |
5068 KB |
Output is correct |
41 |
Correct |
5 ms |
5068 KB |
Output is correct |
42 |
Correct |
5 ms |
5068 KB |
Output is correct |
43 |
Correct |
5 ms |
5068 KB |
Output is correct |
44 |
Correct |
4 ms |
5068 KB |
Output is correct |
45 |
Correct |
6 ms |
5068 KB |
Output is correct |
46 |
Correct |
5 ms |
5068 KB |
Output is correct |
47 |
Correct |
5 ms |
5068 KB |
Output is correct |
48 |
Correct |
5 ms |
5068 KB |
Output is correct |
49 |
Correct |
5 ms |
5072 KB |
Output is correct |
50 |
Correct |
4 ms |
5068 KB |
Output is correct |
51 |
Correct |
5 ms |
5068 KB |
Output is correct |
52 |
Correct |
5 ms |
5068 KB |
Output is correct |
53 |
Correct |
5 ms |
5068 KB |
Output is correct |
54 |
Correct |
5 ms |
5068 KB |
Output is correct |
55 |
Correct |
5 ms |
5068 KB |
Output is correct |
56 |
Correct |
5 ms |
5068 KB |
Output is correct |
57 |
Correct |
5 ms |
5196 KB |
Output is correct |
58 |
Correct |
4 ms |
5068 KB |
Output is correct |
59 |
Correct |
5 ms |
5068 KB |
Output is correct |
60 |
Correct |
5 ms |
5068 KB |
Output is correct |
61 |
Correct |
4 ms |
5068 KB |
Output is correct |
62 |
Correct |
4 ms |
5196 KB |
Output is correct |
63 |
Correct |
4 ms |
5068 KB |
Output is correct |
64 |
Correct |
234 ms |
14228 KB |
Output is correct |
65 |
Correct |
241 ms |
14208 KB |
Output is correct |
66 |
Correct |
248 ms |
14204 KB |
Output is correct |
67 |
Correct |
259 ms |
14256 KB |
Output is correct |
68 |
Correct |
270 ms |
14232 KB |
Output is correct |
69 |
Correct |
260 ms |
14328 KB |
Output is correct |
70 |
Correct |
243 ms |
14296 KB |
Output is correct |
71 |
Correct |
284 ms |
14308 KB |
Output is correct |
72 |
Correct |
267 ms |
14500 KB |
Output is correct |
73 |
Correct |
324 ms |
26256 KB |
Output is correct |
74 |
Correct |
284 ms |
26488 KB |
Output is correct |
75 |
Correct |
258 ms |
16020 KB |
Output is correct |
76 |
Correct |
282 ms |
16152 KB |
Output is correct |
77 |
Correct |
272 ms |
14756 KB |
Output is correct |
78 |
Correct |
244 ms |
14712 KB |
Output is correct |
79 |
Correct |
295 ms |
14740 KB |
Output is correct |
80 |
Correct |
248 ms |
14764 KB |
Output is correct |
81 |
Correct |
223 ms |
14860 KB |
Output is correct |
82 |
Correct |
243 ms |
14780 KB |
Output is correct |
83 |
Correct |
286 ms |
19860 KB |
Output is correct |
84 |
Correct |
271 ms |
22024 KB |
Output is correct |
85 |
Correct |
313 ms |
21720 KB |
Output is correct |
86 |
Correct |
241 ms |
16148 KB |
Output is correct |
87 |
Correct |
242 ms |
15572 KB |
Output is correct |
88 |
Correct |
235 ms |
15620 KB |
Output is correct |
89 |
Correct |
228 ms |
15712 KB |
Output is correct |
90 |
Correct |
223 ms |
15408 KB |
Output is correct |
91 |
Correct |
237 ms |
15692 KB |
Output is correct |
92 |
Correct |
233 ms |
16056 KB |
Output is correct |
93 |
Correct |
227 ms |
18360 KB |
Output is correct |
94 |
Correct |
231 ms |
19964 KB |
Output is correct |
95 |
Correct |
230 ms |
18632 KB |
Output is correct |
96 |
Correct |
225 ms |
16752 KB |
Output is correct |
97 |
Correct |
227 ms |
15400 KB |
Output is correct |
98 |
Correct |
219 ms |
14996 KB |
Output is correct |
99 |
Correct |
229 ms |
14868 KB |
Output is correct |
100 |
Correct |
243 ms |
17716 KB |
Output is correct |
101 |
Correct |
234 ms |
15760 KB |
Output is correct |
102 |
Correct |
230 ms |
15000 KB |
Output is correct |
103 |
Correct |
230 ms |
15124 KB |
Output is correct |
104 |
Correct |
185 ms |
15408 KB |
Output is correct |
105 |
Correct |
259 ms |
23156 KB |
Output is correct |
106 |
Correct |
181 ms |
15380 KB |
Output is correct |
107 |
Correct |
183 ms |
15412 KB |
Output is correct |
108 |
Correct |
266 ms |
27204 KB |
Output is correct |
109 |
Correct |
188 ms |
15316 KB |
Output is correct |
110 |
Correct |
260 ms |
27532 KB |
Output is correct |
111 |
Correct |
237 ms |
14788 KB |
Output is correct |