#include "bits/stdc++.h"
using namespace std;
#define ar array
//~ #define int long long
const int N = 2e3 + 5;
vector<int> edges[N];
int a[N], dp[N];
void dfs(int u, int p = -1){
int cnt = 0;
for(auto x : edges[u]){
if(x == p) continue;
dfs(x, u);
dp[u] += dp[x];
cnt += (dp[x] > 0);
}
dp[u] = max(dp[u] - a[u], a[u]);
}
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n; cin>>n;
for(int i=1;i<n;i++){
int a, b; cin>>a>>b;
edges[a].push_back(b);
edges[b].push_back(a);
} for(int i=1;i<=n;i++){
char c; cin>>c;
a[i] = c - '0';
}
int res = 0;
for(int i=1;i<=n;i++){
memset(dp, 0, sizeof dp);
dfs(i);
//~ cout<<dp[i]<<"\n";
res = max(res, dp[i]);
for(auto x : edges[i]){
if(a[x] && a[i]) res = max(res, 2);
}
} cout<<res<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
360 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
368 KB |
Output is correct |
19 |
Correct |
0 ms |
364 KB |
Output is correct |
20 |
Correct |
0 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
360 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
368 KB |
Output is correct |
19 |
Correct |
0 ms |
364 KB |
Output is correct |
20 |
Correct |
0 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
67 ms |
440 KB |
Output is correct |
23 |
Correct |
71 ms |
440 KB |
Output is correct |
24 |
Correct |
70 ms |
444 KB |
Output is correct |
25 |
Correct |
72 ms |
332 KB |
Output is correct |
26 |
Correct |
68 ms |
460 KB |
Output is correct |
27 |
Correct |
66 ms |
332 KB |
Output is correct |
28 |
Correct |
66 ms |
332 KB |
Output is correct |
29 |
Correct |
84 ms |
708 KB |
Output is correct |
30 |
Correct |
83 ms |
588 KB |
Output is correct |
31 |
Correct |
58 ms |
460 KB |
Output is correct |
32 |
Correct |
57 ms |
332 KB |
Output is correct |
33 |
Correct |
74 ms |
436 KB |
Output is correct |
34 |
Correct |
83 ms |
436 KB |
Output is correct |
35 |
Correct |
75 ms |
436 KB |
Output is correct |
36 |
Correct |
68 ms |
332 KB |
Output is correct |
37 |
Correct |
65 ms |
460 KB |
Output is correct |
38 |
Correct |
61 ms |
460 KB |
Output is correct |
39 |
Correct |
72 ms |
460 KB |
Output is correct |
40 |
Correct |
74 ms |
520 KB |
Output is correct |
41 |
Correct |
77 ms |
512 KB |
Output is correct |
42 |
Correct |
71 ms |
480 KB |
Output is correct |
43 |
Correct |
71 ms |
460 KB |
Output is correct |
44 |
Correct |
63 ms |
484 KB |
Output is correct |
45 |
Correct |
61 ms |
372 KB |
Output is correct |
46 |
Correct |
61 ms |
460 KB |
Output is correct |
47 |
Correct |
62 ms |
468 KB |
Output is correct |
48 |
Correct |
56 ms |
460 KB |
Output is correct |
49 |
Correct |
60 ms |
520 KB |
Output is correct |
50 |
Correct |
55 ms |
496 KB |
Output is correct |
51 |
Correct |
54 ms |
460 KB |
Output is correct |
52 |
Correct |
67 ms |
460 KB |
Output is correct |
53 |
Correct |
61 ms |
496 KB |
Output is correct |
54 |
Correct |
59 ms |
480 KB |
Output is correct |
55 |
Correct |
63 ms |
464 KB |
Output is correct |
56 |
Correct |
30 ms |
376 KB |
Output is correct |
57 |
Correct |
82 ms |
592 KB |
Output is correct |
58 |
Correct |
30 ms |
460 KB |
Output is correct |
59 |
Correct |
29 ms |
460 KB |
Output is correct |
60 |
Correct |
80 ms |
588 KB |
Output is correct |
61 |
Correct |
32 ms |
420 KB |
Output is correct |
62 |
Correct |
84 ms |
588 KB |
Output is correct |
63 |
Correct |
52 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
360 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
368 KB |
Output is correct |
19 |
Correct |
0 ms |
364 KB |
Output is correct |
20 |
Correct |
0 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
67 ms |
440 KB |
Output is correct |
23 |
Correct |
71 ms |
440 KB |
Output is correct |
24 |
Correct |
70 ms |
444 KB |
Output is correct |
25 |
Correct |
72 ms |
332 KB |
Output is correct |
26 |
Correct |
68 ms |
460 KB |
Output is correct |
27 |
Correct |
66 ms |
332 KB |
Output is correct |
28 |
Correct |
66 ms |
332 KB |
Output is correct |
29 |
Correct |
84 ms |
708 KB |
Output is correct |
30 |
Correct |
83 ms |
588 KB |
Output is correct |
31 |
Correct |
58 ms |
460 KB |
Output is correct |
32 |
Correct |
57 ms |
332 KB |
Output is correct |
33 |
Correct |
74 ms |
436 KB |
Output is correct |
34 |
Correct |
83 ms |
436 KB |
Output is correct |
35 |
Correct |
75 ms |
436 KB |
Output is correct |
36 |
Correct |
68 ms |
332 KB |
Output is correct |
37 |
Correct |
65 ms |
460 KB |
Output is correct |
38 |
Correct |
61 ms |
460 KB |
Output is correct |
39 |
Correct |
72 ms |
460 KB |
Output is correct |
40 |
Correct |
74 ms |
520 KB |
Output is correct |
41 |
Correct |
77 ms |
512 KB |
Output is correct |
42 |
Correct |
71 ms |
480 KB |
Output is correct |
43 |
Correct |
71 ms |
460 KB |
Output is correct |
44 |
Correct |
63 ms |
484 KB |
Output is correct |
45 |
Correct |
61 ms |
372 KB |
Output is correct |
46 |
Correct |
61 ms |
460 KB |
Output is correct |
47 |
Correct |
62 ms |
468 KB |
Output is correct |
48 |
Correct |
56 ms |
460 KB |
Output is correct |
49 |
Correct |
60 ms |
520 KB |
Output is correct |
50 |
Correct |
55 ms |
496 KB |
Output is correct |
51 |
Correct |
54 ms |
460 KB |
Output is correct |
52 |
Correct |
67 ms |
460 KB |
Output is correct |
53 |
Correct |
61 ms |
496 KB |
Output is correct |
54 |
Correct |
59 ms |
480 KB |
Output is correct |
55 |
Correct |
63 ms |
464 KB |
Output is correct |
56 |
Correct |
30 ms |
376 KB |
Output is correct |
57 |
Correct |
82 ms |
592 KB |
Output is correct |
58 |
Correct |
30 ms |
460 KB |
Output is correct |
59 |
Correct |
29 ms |
460 KB |
Output is correct |
60 |
Correct |
80 ms |
588 KB |
Output is correct |
61 |
Correct |
32 ms |
420 KB |
Output is correct |
62 |
Correct |
84 ms |
588 KB |
Output is correct |
63 |
Correct |
52 ms |
332 KB |
Output is correct |
64 |
Runtime error |
1 ms |
588 KB |
Execution killed with signal 11 |
65 |
Halted |
0 ms |
0 KB |
- |