//雪花飄飄北風嘯嘯
//天地一片蒼茫
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
int n;
vector<int> al[200005];
string s;
map<ii,int> memo;
int par[200005];
int val[200005];
int dfs(int i,int p){
if (memo.count(ii(i,p))) return memo[ii(i,p)];
int res=0;
if (par[i]==-2){
for (auto &it:al[i]){
if (it==p) continue;
res+=dfs(it,i);
}
par[i]=p;
val[i]=res;
}
else{
res=val[i];
if (par[i]!=-1) res+=dfs(par[i],i);
if (p!=-1) res-=dfs(p,i);
}
res+=(s[i]=='1'?-1:0);
return memo[ii(i,p)]=max(res,(s[i]=='1'?1:0));
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin.exceptions(ios::badbit | ios::failbit);
cin>>n;
rep(x,0,n) par[x]=-2;
int a,b;
rep(x,1,n){
cin>>a>>b;
a--,b--;
al[a].push_back(b);
al[b].push_back(a);
}
cin>>s;
int ans=0;
rep(x,0,n) if (s[x]=='1') ans++;
ans=min(ans,2);
rep(x,0,n){
ans=max(dfs(x,-1),ans);
}
cout<<ans<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
4992 KB |
Output is correct |
6 |
Correct |
4 ms |
4992 KB |
Output is correct |
7 |
Correct |
4 ms |
4992 KB |
Output is correct |
8 |
Correct |
4 ms |
4992 KB |
Output is correct |
9 |
Correct |
4 ms |
4992 KB |
Output is correct |
10 |
Correct |
4 ms |
4992 KB |
Output is correct |
11 |
Correct |
3 ms |
4992 KB |
Output is correct |
12 |
Correct |
4 ms |
4992 KB |
Output is correct |
13 |
Correct |
3 ms |
4992 KB |
Output is correct |
14 |
Correct |
3 ms |
4992 KB |
Output is correct |
15 |
Correct |
3 ms |
4992 KB |
Output is correct |
16 |
Correct |
3 ms |
4992 KB |
Output is correct |
17 |
Correct |
4 ms |
4992 KB |
Output is correct |
18 |
Correct |
4 ms |
4992 KB |
Output is correct |
19 |
Correct |
4 ms |
4992 KB |
Output is correct |
20 |
Correct |
3 ms |
4992 KB |
Output is correct |
21 |
Correct |
4 ms |
4992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
4992 KB |
Output is correct |
6 |
Correct |
4 ms |
4992 KB |
Output is correct |
7 |
Correct |
4 ms |
4992 KB |
Output is correct |
8 |
Correct |
4 ms |
4992 KB |
Output is correct |
9 |
Correct |
4 ms |
4992 KB |
Output is correct |
10 |
Correct |
4 ms |
4992 KB |
Output is correct |
11 |
Correct |
3 ms |
4992 KB |
Output is correct |
12 |
Correct |
4 ms |
4992 KB |
Output is correct |
13 |
Correct |
3 ms |
4992 KB |
Output is correct |
14 |
Correct |
3 ms |
4992 KB |
Output is correct |
15 |
Correct |
3 ms |
4992 KB |
Output is correct |
16 |
Correct |
3 ms |
4992 KB |
Output is correct |
17 |
Correct |
4 ms |
4992 KB |
Output is correct |
18 |
Correct |
4 ms |
4992 KB |
Output is correct |
19 |
Correct |
4 ms |
4992 KB |
Output is correct |
20 |
Correct |
3 ms |
4992 KB |
Output is correct |
21 |
Correct |
4 ms |
4992 KB |
Output is correct |
22 |
Correct |
7 ms |
5504 KB |
Output is correct |
23 |
Correct |
7 ms |
5504 KB |
Output is correct |
24 |
Correct |
7 ms |
5504 KB |
Output is correct |
25 |
Correct |
9 ms |
5504 KB |
Output is correct |
26 |
Correct |
7 ms |
5504 KB |
Output is correct |
27 |
Correct |
7 ms |
5504 KB |
Output is correct |
28 |
Correct |
8 ms |
5504 KB |
Output is correct |
29 |
Correct |
7 ms |
5760 KB |
Output is correct |
30 |
Correct |
8 ms |
5760 KB |
Output is correct |
31 |
Correct |
9 ms |
5504 KB |
Output is correct |
32 |
Correct |
7 ms |
5504 KB |
Output is correct |
33 |
Correct |
7 ms |
5504 KB |
Output is correct |
34 |
Correct |
7 ms |
5504 KB |
Output is correct |
35 |
Correct |
7 ms |
5504 KB |
Output is correct |
36 |
Correct |
7 ms |
5504 KB |
Output is correct |
37 |
Correct |
7 ms |
5504 KB |
Output is correct |
38 |
Correct |
7 ms |
5504 KB |
Output is correct |
39 |
Correct |
7 ms |
5632 KB |
Output is correct |
40 |
Correct |
8 ms |
5632 KB |
Output is correct |
41 |
Correct |
7 ms |
5632 KB |
Output is correct |
42 |
Correct |
7 ms |
5504 KB |
Output is correct |
43 |
Correct |
7 ms |
5504 KB |
Output is correct |
44 |
Correct |
7 ms |
5504 KB |
Output is correct |
45 |
Correct |
8 ms |
5504 KB |
Output is correct |
46 |
Correct |
7 ms |
5504 KB |
Output is correct |
47 |
Correct |
7 ms |
5504 KB |
Output is correct |
48 |
Correct |
7 ms |
5632 KB |
Output is correct |
49 |
Correct |
7 ms |
5632 KB |
Output is correct |
50 |
Correct |
7 ms |
5504 KB |
Output is correct |
51 |
Correct |
7 ms |
5504 KB |
Output is correct |
52 |
Correct |
7 ms |
5504 KB |
Output is correct |
53 |
Correct |
7 ms |
5504 KB |
Output is correct |
54 |
Correct |
7 ms |
5504 KB |
Output is correct |
55 |
Correct |
7 ms |
5504 KB |
Output is correct |
56 |
Correct |
6 ms |
5504 KB |
Output is correct |
57 |
Correct |
7 ms |
5760 KB |
Output is correct |
58 |
Correct |
6 ms |
5504 KB |
Output is correct |
59 |
Correct |
6 ms |
5504 KB |
Output is correct |
60 |
Correct |
7 ms |
5632 KB |
Output is correct |
61 |
Correct |
6 ms |
5504 KB |
Output is correct |
62 |
Correct |
7 ms |
5760 KB |
Output is correct |
63 |
Correct |
7 ms |
5504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
4992 KB |
Output is correct |
6 |
Correct |
4 ms |
4992 KB |
Output is correct |
7 |
Correct |
4 ms |
4992 KB |
Output is correct |
8 |
Correct |
4 ms |
4992 KB |
Output is correct |
9 |
Correct |
4 ms |
4992 KB |
Output is correct |
10 |
Correct |
4 ms |
4992 KB |
Output is correct |
11 |
Correct |
3 ms |
4992 KB |
Output is correct |
12 |
Correct |
4 ms |
4992 KB |
Output is correct |
13 |
Correct |
3 ms |
4992 KB |
Output is correct |
14 |
Correct |
3 ms |
4992 KB |
Output is correct |
15 |
Correct |
3 ms |
4992 KB |
Output is correct |
16 |
Correct |
3 ms |
4992 KB |
Output is correct |
17 |
Correct |
4 ms |
4992 KB |
Output is correct |
18 |
Correct |
4 ms |
4992 KB |
Output is correct |
19 |
Correct |
4 ms |
4992 KB |
Output is correct |
20 |
Correct |
3 ms |
4992 KB |
Output is correct |
21 |
Correct |
4 ms |
4992 KB |
Output is correct |
22 |
Correct |
7 ms |
5504 KB |
Output is correct |
23 |
Correct |
7 ms |
5504 KB |
Output is correct |
24 |
Correct |
7 ms |
5504 KB |
Output is correct |
25 |
Correct |
9 ms |
5504 KB |
Output is correct |
26 |
Correct |
7 ms |
5504 KB |
Output is correct |
27 |
Correct |
7 ms |
5504 KB |
Output is correct |
28 |
Correct |
8 ms |
5504 KB |
Output is correct |
29 |
Correct |
7 ms |
5760 KB |
Output is correct |
30 |
Correct |
8 ms |
5760 KB |
Output is correct |
31 |
Correct |
9 ms |
5504 KB |
Output is correct |
32 |
Correct |
7 ms |
5504 KB |
Output is correct |
33 |
Correct |
7 ms |
5504 KB |
Output is correct |
34 |
Correct |
7 ms |
5504 KB |
Output is correct |
35 |
Correct |
7 ms |
5504 KB |
Output is correct |
36 |
Correct |
7 ms |
5504 KB |
Output is correct |
37 |
Correct |
7 ms |
5504 KB |
Output is correct |
38 |
Correct |
7 ms |
5504 KB |
Output is correct |
39 |
Correct |
7 ms |
5632 KB |
Output is correct |
40 |
Correct |
8 ms |
5632 KB |
Output is correct |
41 |
Correct |
7 ms |
5632 KB |
Output is correct |
42 |
Correct |
7 ms |
5504 KB |
Output is correct |
43 |
Correct |
7 ms |
5504 KB |
Output is correct |
44 |
Correct |
7 ms |
5504 KB |
Output is correct |
45 |
Correct |
8 ms |
5504 KB |
Output is correct |
46 |
Correct |
7 ms |
5504 KB |
Output is correct |
47 |
Correct |
7 ms |
5504 KB |
Output is correct |
48 |
Correct |
7 ms |
5632 KB |
Output is correct |
49 |
Correct |
7 ms |
5632 KB |
Output is correct |
50 |
Correct |
7 ms |
5504 KB |
Output is correct |
51 |
Correct |
7 ms |
5504 KB |
Output is correct |
52 |
Correct |
7 ms |
5504 KB |
Output is correct |
53 |
Correct |
7 ms |
5504 KB |
Output is correct |
54 |
Correct |
7 ms |
5504 KB |
Output is correct |
55 |
Correct |
7 ms |
5504 KB |
Output is correct |
56 |
Correct |
6 ms |
5504 KB |
Output is correct |
57 |
Correct |
7 ms |
5760 KB |
Output is correct |
58 |
Correct |
6 ms |
5504 KB |
Output is correct |
59 |
Correct |
6 ms |
5504 KB |
Output is correct |
60 |
Correct |
7 ms |
5632 KB |
Output is correct |
61 |
Correct |
6 ms |
5504 KB |
Output is correct |
62 |
Correct |
7 ms |
5760 KB |
Output is correct |
63 |
Correct |
7 ms |
5504 KB |
Output is correct |
64 |
Correct |
1004 ms |
50752 KB |
Output is correct |
65 |
Correct |
1072 ms |
50872 KB |
Output is correct |
66 |
Correct |
1020 ms |
50848 KB |
Output is correct |
67 |
Correct |
1020 ms |
50840 KB |
Output is correct |
68 |
Correct |
1010 ms |
50736 KB |
Output is correct |
69 |
Correct |
1025 ms |
50936 KB |
Output is correct |
70 |
Correct |
1010 ms |
50756 KB |
Output is correct |
71 |
Correct |
1018 ms |
50880 KB |
Output is correct |
72 |
Correct |
1010 ms |
50864 KB |
Output is correct |
73 |
Correct |
1136 ms |
73548 KB |
Output is correct |
74 |
Correct |
1183 ms |
73656 KB |
Output is correct |
75 |
Correct |
1006 ms |
50604 KB |
Output is correct |
76 |
Correct |
1080 ms |
50624 KB |
Output is correct |
77 |
Correct |
1084 ms |
50748 KB |
Output is correct |
78 |
Correct |
1034 ms |
50844 KB |
Output is correct |
79 |
Correct |
1073 ms |
50752 KB |
Output is correct |
80 |
Correct |
1038 ms |
50744 KB |
Output is correct |
81 |
Correct |
890 ms |
51316 KB |
Output is correct |
82 |
Correct |
992 ms |
50936 KB |
Output is correct |
83 |
Correct |
1094 ms |
60140 KB |
Output is correct |
84 |
Correct |
1082 ms |
63896 KB |
Output is correct |
85 |
Correct |
1094 ms |
63296 KB |
Output is correct |
86 |
Correct |
1077 ms |
53304 KB |
Output is correct |
87 |
Correct |
1048 ms |
52148 KB |
Output is correct |
88 |
Correct |
1079 ms |
52468 KB |
Output is correct |
89 |
Correct |
1055 ms |
52580 KB |
Output is correct |
90 |
Correct |
1082 ms |
52124 KB |
Output is correct |
91 |
Correct |
1072 ms |
52584 KB |
Output is correct |
92 |
Correct |
1100 ms |
53160 KB |
Output is correct |
93 |
Correct |
944 ms |
57860 KB |
Output is correct |
94 |
Correct |
964 ms |
60784 KB |
Output is correct |
95 |
Correct |
913 ms |
58324 KB |
Output is correct |
96 |
Correct |
1055 ms |
55048 KB |
Output is correct |
97 |
Correct |
1049 ms |
52268 KB |
Output is correct |
98 |
Correct |
1121 ms |
51452 KB |
Output is correct |
99 |
Correct |
1025 ms |
51216 KB |
Output is correct |
100 |
Correct |
949 ms |
56868 KB |
Output is correct |
101 |
Correct |
1092 ms |
53348 KB |
Output is correct |
102 |
Correct |
994 ms |
51972 KB |
Output is correct |
103 |
Correct |
1070 ms |
51420 KB |
Output is correct |
104 |
Correct |
625 ms |
51580 KB |
Output is correct |
105 |
Correct |
1158 ms |
67856 KB |
Output is correct |
106 |
Correct |
613 ms |
51440 KB |
Output is correct |
107 |
Correct |
606 ms |
51380 KB |
Output is correct |
108 |
Correct |
1252 ms |
74880 KB |
Output is correct |
109 |
Correct |
623 ms |
51380 KB |
Output is correct |
110 |
Correct |
1177 ms |
75576 KB |
Output is correct |
111 |
Correct |
1000 ms |
50776 KB |
Output is correct |