#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define FOR(i, a, b) for ( int i = a ; i <= b ; i++ )
#define FORD(i, a, b) for (int i = b; i >= a; i --)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPD(i, n) for (int i = n - 1; i >= 0; --i)
#define pii pair<int , int>
#define Lg(x) 31 - __builtin_clz(x)
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int MAX = 2e5 + 5;
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void setupIO(){
#define name "Whisper"
//Phu Trong from Nguyen Tat Thanh High School for gifted student
srand(time(NULL));
cin.tie(nullptr)->sync_with_stdio(false); cout.tie(nullptr);
//freopen(name".inp", "r", stdin);
//freopen(name".out", "w", stdout);
cout << fixed << setprecision(10);
}
template <class X, class Y>
bool minimize(X &x, const Y &y){
X eps = 1e-9;
if (x > y + eps) {x = y; return 1;}
return 0;
}
template <class X, class Y>
bool maximize(X &x, const Y &y){
X eps = 1e-9;
if (x + eps < y) {x = y; return 1;}
return 0;
}
int numNode;
vector<int> adj[MAX];
string s;
int dp[MAX];
int hasGen[MAX];
int ans = 0;
void dfs(int u, int p){
int pre_ans = 0;
for (auto&v : adj[u]) if(v ^ p){
dfs(v, u);
dp[u] += dp[v];
maximize(pre_ans, dp[v]);
}
if (hasGen[u]){
dp[u] = max(dp[u] - 1, 1ll);
pre_ans++;
}
maximize(ans, max(pre_ans, dp[u]));
}
void Whisper(){
cin >> numNode;
for (int i = 1; i < numNode; ++i){
int u, v; cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
cin >> s;
REP(i, numNode){
hasGen[i + 1] = (s[i] == '1');
}
dfs(1, 0);
cout << ans;
}
signed main(){
setupIO();
int Test = 1;
// cin >> Test;
for ( int i = 1 ; i <= Test ; i++ ){
Whisper();
if (i < Test) cout << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5976 KB |
Output is correct |
2 |
Correct |
2 ms |
5980 KB |
Output is correct |
3 |
Correct |
2 ms |
5980 KB |
Output is correct |
4 |
Correct |
2 ms |
5980 KB |
Output is correct |
5 |
Correct |
2 ms |
6232 KB |
Output is correct |
6 |
Correct |
2 ms |
5980 KB |
Output is correct |
7 |
Correct |
2 ms |
5980 KB |
Output is correct |
8 |
Correct |
2 ms |
5980 KB |
Output is correct |
9 |
Correct |
2 ms |
5980 KB |
Output is correct |
10 |
Correct |
2 ms |
5980 KB |
Output is correct |
11 |
Correct |
2 ms |
5980 KB |
Output is correct |
12 |
Correct |
2 ms |
5980 KB |
Output is correct |
13 |
Correct |
2 ms |
5976 KB |
Output is correct |
14 |
Correct |
2 ms |
5976 KB |
Output is correct |
15 |
Correct |
2 ms |
5980 KB |
Output is correct |
16 |
Correct |
2 ms |
5980 KB |
Output is correct |
17 |
Correct |
2 ms |
5980 KB |
Output is correct |
18 |
Correct |
2 ms |
5976 KB |
Output is correct |
19 |
Correct |
2 ms |
5980 KB |
Output is correct |
20 |
Correct |
2 ms |
5980 KB |
Output is correct |
21 |
Correct |
2 ms |
5980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5976 KB |
Output is correct |
2 |
Correct |
2 ms |
5980 KB |
Output is correct |
3 |
Correct |
2 ms |
5980 KB |
Output is correct |
4 |
Correct |
2 ms |
5980 KB |
Output is correct |
5 |
Correct |
2 ms |
6232 KB |
Output is correct |
6 |
Correct |
2 ms |
5980 KB |
Output is correct |
7 |
Correct |
2 ms |
5980 KB |
Output is correct |
8 |
Correct |
2 ms |
5980 KB |
Output is correct |
9 |
Correct |
2 ms |
5980 KB |
Output is correct |
10 |
Correct |
2 ms |
5980 KB |
Output is correct |
11 |
Correct |
2 ms |
5980 KB |
Output is correct |
12 |
Correct |
2 ms |
5980 KB |
Output is correct |
13 |
Correct |
2 ms |
5976 KB |
Output is correct |
14 |
Correct |
2 ms |
5976 KB |
Output is correct |
15 |
Correct |
2 ms |
5980 KB |
Output is correct |
16 |
Correct |
2 ms |
5980 KB |
Output is correct |
17 |
Correct |
2 ms |
5980 KB |
Output is correct |
18 |
Correct |
2 ms |
5976 KB |
Output is correct |
19 |
Correct |
2 ms |
5980 KB |
Output is correct |
20 |
Correct |
2 ms |
5980 KB |
Output is correct |
21 |
Correct |
2 ms |
5980 KB |
Output is correct |
22 |
Correct |
2 ms |
5980 KB |
Output is correct |
23 |
Correct |
3 ms |
5980 KB |
Output is correct |
24 |
Correct |
2 ms |
5980 KB |
Output is correct |
25 |
Correct |
3 ms |
5980 KB |
Output is correct |
26 |
Correct |
2 ms |
5980 KB |
Output is correct |
27 |
Correct |
3 ms |
5976 KB |
Output is correct |
28 |
Correct |
2 ms |
5976 KB |
Output is correct |
29 |
Correct |
3 ms |
6236 KB |
Output is correct |
30 |
Correct |
2 ms |
6236 KB |
Output is correct |
31 |
Correct |
2 ms |
5980 KB |
Output is correct |
32 |
Correct |
2 ms |
6076 KB |
Output is correct |
33 |
Correct |
2 ms |
5980 KB |
Output is correct |
34 |
Correct |
2 ms |
5980 KB |
Output is correct |
35 |
Correct |
3 ms |
5980 KB |
Output is correct |
36 |
Correct |
2 ms |
5980 KB |
Output is correct |
37 |
Correct |
2 ms |
5980 KB |
Output is correct |
38 |
Correct |
3 ms |
5980 KB |
Output is correct |
39 |
Correct |
2 ms |
6236 KB |
Output is correct |
40 |
Correct |
3 ms |
5980 KB |
Output is correct |
41 |
Correct |
2 ms |
6436 KB |
Output is correct |
42 |
Correct |
2 ms |
5976 KB |
Output is correct |
43 |
Correct |
2 ms |
5980 KB |
Output is correct |
44 |
Correct |
2 ms |
5980 KB |
Output is correct |
45 |
Correct |
2 ms |
5980 KB |
Output is correct |
46 |
Correct |
3 ms |
5980 KB |
Output is correct |
47 |
Correct |
2 ms |
5980 KB |
Output is correct |
48 |
Correct |
3 ms |
6236 KB |
Output is correct |
49 |
Correct |
2 ms |
6236 KB |
Output is correct |
50 |
Correct |
3 ms |
5980 KB |
Output is correct |
51 |
Correct |
2 ms |
5980 KB |
Output is correct |
52 |
Correct |
2 ms |
5980 KB |
Output is correct |
53 |
Correct |
2 ms |
5980 KB |
Output is correct |
54 |
Correct |
3 ms |
6084 KB |
Output is correct |
55 |
Correct |
2 ms |
5980 KB |
Output is correct |
56 |
Correct |
2 ms |
5980 KB |
Output is correct |
57 |
Correct |
3 ms |
6236 KB |
Output is correct |
58 |
Correct |
2 ms |
5980 KB |
Output is correct |
59 |
Correct |
3 ms |
5980 KB |
Output is correct |
60 |
Correct |
2 ms |
6236 KB |
Output is correct |
61 |
Correct |
2 ms |
5980 KB |
Output is correct |
62 |
Correct |
2 ms |
6236 KB |
Output is correct |
63 |
Correct |
2 ms |
5976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5976 KB |
Output is correct |
2 |
Correct |
2 ms |
5980 KB |
Output is correct |
3 |
Correct |
2 ms |
5980 KB |
Output is correct |
4 |
Correct |
2 ms |
5980 KB |
Output is correct |
5 |
Correct |
2 ms |
6232 KB |
Output is correct |
6 |
Correct |
2 ms |
5980 KB |
Output is correct |
7 |
Correct |
2 ms |
5980 KB |
Output is correct |
8 |
Correct |
2 ms |
5980 KB |
Output is correct |
9 |
Correct |
2 ms |
5980 KB |
Output is correct |
10 |
Correct |
2 ms |
5980 KB |
Output is correct |
11 |
Correct |
2 ms |
5980 KB |
Output is correct |
12 |
Correct |
2 ms |
5980 KB |
Output is correct |
13 |
Correct |
2 ms |
5976 KB |
Output is correct |
14 |
Correct |
2 ms |
5976 KB |
Output is correct |
15 |
Correct |
2 ms |
5980 KB |
Output is correct |
16 |
Correct |
2 ms |
5980 KB |
Output is correct |
17 |
Correct |
2 ms |
5980 KB |
Output is correct |
18 |
Correct |
2 ms |
5976 KB |
Output is correct |
19 |
Correct |
2 ms |
5980 KB |
Output is correct |
20 |
Correct |
2 ms |
5980 KB |
Output is correct |
21 |
Correct |
2 ms |
5980 KB |
Output is correct |
22 |
Correct |
2 ms |
5980 KB |
Output is correct |
23 |
Correct |
3 ms |
5980 KB |
Output is correct |
24 |
Correct |
2 ms |
5980 KB |
Output is correct |
25 |
Correct |
3 ms |
5980 KB |
Output is correct |
26 |
Correct |
2 ms |
5980 KB |
Output is correct |
27 |
Correct |
3 ms |
5976 KB |
Output is correct |
28 |
Correct |
2 ms |
5976 KB |
Output is correct |
29 |
Correct |
3 ms |
6236 KB |
Output is correct |
30 |
Correct |
2 ms |
6236 KB |
Output is correct |
31 |
Correct |
2 ms |
5980 KB |
Output is correct |
32 |
Correct |
2 ms |
6076 KB |
Output is correct |
33 |
Correct |
2 ms |
5980 KB |
Output is correct |
34 |
Correct |
2 ms |
5980 KB |
Output is correct |
35 |
Correct |
3 ms |
5980 KB |
Output is correct |
36 |
Correct |
2 ms |
5980 KB |
Output is correct |
37 |
Correct |
2 ms |
5980 KB |
Output is correct |
38 |
Correct |
3 ms |
5980 KB |
Output is correct |
39 |
Correct |
2 ms |
6236 KB |
Output is correct |
40 |
Correct |
3 ms |
5980 KB |
Output is correct |
41 |
Correct |
2 ms |
6436 KB |
Output is correct |
42 |
Correct |
2 ms |
5976 KB |
Output is correct |
43 |
Correct |
2 ms |
5980 KB |
Output is correct |
44 |
Correct |
2 ms |
5980 KB |
Output is correct |
45 |
Correct |
2 ms |
5980 KB |
Output is correct |
46 |
Correct |
3 ms |
5980 KB |
Output is correct |
47 |
Correct |
2 ms |
5980 KB |
Output is correct |
48 |
Correct |
3 ms |
6236 KB |
Output is correct |
49 |
Correct |
2 ms |
6236 KB |
Output is correct |
50 |
Correct |
3 ms |
5980 KB |
Output is correct |
51 |
Correct |
2 ms |
5980 KB |
Output is correct |
52 |
Correct |
2 ms |
5980 KB |
Output is correct |
53 |
Correct |
2 ms |
5980 KB |
Output is correct |
54 |
Correct |
3 ms |
6084 KB |
Output is correct |
55 |
Correct |
2 ms |
5980 KB |
Output is correct |
56 |
Correct |
2 ms |
5980 KB |
Output is correct |
57 |
Correct |
3 ms |
6236 KB |
Output is correct |
58 |
Correct |
2 ms |
5980 KB |
Output is correct |
59 |
Correct |
3 ms |
5980 KB |
Output is correct |
60 |
Correct |
2 ms |
6236 KB |
Output is correct |
61 |
Correct |
2 ms |
5980 KB |
Output is correct |
62 |
Correct |
2 ms |
6236 KB |
Output is correct |
63 |
Correct |
2 ms |
5976 KB |
Output is correct |
64 |
Correct |
79 ms |
18576 KB |
Output is correct |
65 |
Correct |
83 ms |
18700 KB |
Output is correct |
66 |
Correct |
105 ms |
18560 KB |
Output is correct |
67 |
Correct |
69 ms |
18572 KB |
Output is correct |
68 |
Correct |
68 ms |
18512 KB |
Output is correct |
69 |
Correct |
95 ms |
19020 KB |
Output is correct |
70 |
Correct |
66 ms |
18552 KB |
Output is correct |
71 |
Correct |
78 ms |
18592 KB |
Output is correct |
72 |
Correct |
97 ms |
18672 KB |
Output is correct |
73 |
Correct |
84 ms |
27576 KB |
Output is correct |
74 |
Correct |
101 ms |
27536 KB |
Output is correct |
75 |
Correct |
72 ms |
19852 KB |
Output is correct |
76 |
Correct |
102 ms |
19768 KB |
Output is correct |
77 |
Correct |
69 ms |
18484 KB |
Output is correct |
78 |
Correct |
74 ms |
18576 KB |
Output is correct |
79 |
Correct |
72 ms |
18536 KB |
Output is correct |
80 |
Correct |
107 ms |
18568 KB |
Output is correct |
81 |
Correct |
58 ms |
18836 KB |
Output is correct |
82 |
Correct |
89 ms |
18640 KB |
Output is correct |
83 |
Correct |
100 ms |
22592 KB |
Output is correct |
84 |
Correct |
89 ms |
24340 KB |
Output is correct |
85 |
Correct |
87 ms |
23964 KB |
Output is correct |
86 |
Correct |
77 ms |
19600 KB |
Output is correct |
87 |
Correct |
104 ms |
19128 KB |
Output is correct |
88 |
Correct |
108 ms |
19276 KB |
Output is correct |
89 |
Correct |
73 ms |
19356 KB |
Output is correct |
90 |
Correct |
71 ms |
19076 KB |
Output is correct |
91 |
Correct |
73 ms |
19320 KB |
Output is correct |
92 |
Correct |
71 ms |
19696 KB |
Output is correct |
93 |
Correct |
95 ms |
21228 KB |
Output is correct |
94 |
Correct |
71 ms |
22704 KB |
Output is correct |
95 |
Correct |
133 ms |
21692 KB |
Output is correct |
96 |
Correct |
80 ms |
20284 KB |
Output is correct |
97 |
Correct |
65 ms |
18944 KB |
Output is correct |
98 |
Correct |
62 ms |
18648 KB |
Output is correct |
99 |
Correct |
74 ms |
18580 KB |
Output is correct |
100 |
Correct |
92 ms |
20856 KB |
Output is correct |
101 |
Correct |
65 ms |
19216 KB |
Output is correct |
102 |
Correct |
65 ms |
18788 KB |
Output is correct |
103 |
Correct |
100 ms |
18860 KB |
Output is correct |
104 |
Correct |
64 ms |
19136 KB |
Output is correct |
105 |
Correct |
109 ms |
24984 KB |
Output is correct |
106 |
Correct |
48 ms |
19152 KB |
Output is correct |
107 |
Correct |
69 ms |
19136 KB |
Output is correct |
108 |
Correct |
147 ms |
28136 KB |
Output is correct |
109 |
Correct |
47 ms |
19136 KB |
Output is correct |
110 |
Correct |
100 ms |
28392 KB |
Output is correct |
111 |
Correct |
78 ms |
18592 KB |
Output is correct |