#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a))
#define MEM_1(a) memset((a),-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define COMPRESS(a) sort(ALL(a));a.resize(unique(ALL(a))-a.begin())
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<ld> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 };
char s[200005];
Vi v[200005];
int ans;
int dfs(int N,int p=-1){
int res=0;
for(int next:v[N]){
if(next==p)continue;
int t=dfs(next,N);
if(s[N]=='1')ans=max(ans,t+1);
res+=t;
}
if(s[N]=='1'){
res=max(1,res-1);
}
ans=max(ans,res);
return res;
}
int main(){
int n;
scanf("%d",&n);
fup(i,1,n-1,1){
int x,y;
scanf("%d%d",&x,&y);
v[x].pb(y);
v[y].pb(x);
}
scanf("%s",s+1);
dfs(1);
printf("%d\n",ans);
}
Compilation message
power.cpp: In function 'int main()':
power.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
| ^
power.cpp:63:2: note: in expansion of macro 'fup'
63 | fup(i,1,n-1,1){
| ^~~
power.cpp:62:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
62 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
power.cpp:65:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
65 | scanf("%d%d",&x,&y);
| ~~~~~^~~~~~~~~~~~~~
power.cpp:69:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
69 | scanf("%s",s+1);
| ~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5004 KB |
Output is correct |
2 |
Correct |
4 ms |
5000 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5000 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 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 |
4 ms |
4948 KB |
Output is correct |
11 |
Correct |
4 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
4 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4952 KB |
Output is correct |
17 |
Correct |
3 ms |
5008 KB |
Output is correct |
18 |
Correct |
4 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4900 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5004 KB |
Output is correct |
2 |
Correct |
4 ms |
5000 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5000 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 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 |
4 ms |
4948 KB |
Output is correct |
11 |
Correct |
4 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
4 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4952 KB |
Output is correct |
17 |
Correct |
3 ms |
5008 KB |
Output is correct |
18 |
Correct |
4 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4900 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
5076 KB |
Output is correct |
23 |
Correct |
3 ms |
5076 KB |
Output is correct |
24 |
Correct |
3 ms |
5076 KB |
Output is correct |
25 |
Correct |
4 ms |
5076 KB |
Output is correct |
26 |
Correct |
4 ms |
5016 KB |
Output is correct |
27 |
Correct |
3 ms |
5076 KB |
Output is correct |
28 |
Correct |
4 ms |
5076 KB |
Output is correct |
29 |
Correct |
5 ms |
5204 KB |
Output is correct |
30 |
Correct |
4 ms |
5148 KB |
Output is correct |
31 |
Correct |
4 ms |
5020 KB |
Output is correct |
32 |
Correct |
4 ms |
5076 KB |
Output is correct |
33 |
Correct |
4 ms |
5076 KB |
Output is correct |
34 |
Correct |
3 ms |
5076 KB |
Output is correct |
35 |
Correct |
3 ms |
5020 KB |
Output is correct |
36 |
Correct |
5 ms |
5072 KB |
Output is correct |
37 |
Correct |
3 ms |
5076 KB |
Output is correct |
38 |
Correct |
3 ms |
5076 KB |
Output is correct |
39 |
Correct |
4 ms |
5144 KB |
Output is correct |
40 |
Correct |
4 ms |
5076 KB |
Output is correct |
41 |
Correct |
4 ms |
5148 KB |
Output is correct |
42 |
Correct |
4 ms |
5076 KB |
Output is correct |
43 |
Correct |
3 ms |
5012 KB |
Output is correct |
44 |
Correct |
4 ms |
5076 KB |
Output is correct |
45 |
Correct |
5 ms |
5076 KB |
Output is correct |
46 |
Correct |
5 ms |
5076 KB |
Output is correct |
47 |
Correct |
5 ms |
5016 KB |
Output is correct |
48 |
Correct |
4 ms |
5076 KB |
Output is correct |
49 |
Correct |
4 ms |
5140 KB |
Output is correct |
50 |
Correct |
5 ms |
5012 KB |
Output is correct |
51 |
Correct |
4 ms |
5076 KB |
Output is correct |
52 |
Correct |
3 ms |
5076 KB |
Output is correct |
53 |
Correct |
4 ms |
5012 KB |
Output is correct |
54 |
Correct |
3 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 |
3 ms |
5204 KB |
Output is correct |
58 |
Correct |
3 ms |
5012 KB |
Output is correct |
59 |
Correct |
3 ms |
5076 KB |
Output is correct |
60 |
Correct |
4 ms |
5076 KB |
Output is correct |
61 |
Correct |
3 ms |
5076 KB |
Output is correct |
62 |
Correct |
4 ms |
5076 KB |
Output is correct |
63 |
Correct |
4 ms |
5076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5004 KB |
Output is correct |
2 |
Correct |
4 ms |
5000 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5000 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 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 |
4 ms |
4948 KB |
Output is correct |
11 |
Correct |
4 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
4 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4952 KB |
Output is correct |
17 |
Correct |
3 ms |
5008 KB |
Output is correct |
18 |
Correct |
4 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4900 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
5076 KB |
Output is correct |
23 |
Correct |
3 ms |
5076 KB |
Output is correct |
24 |
Correct |
3 ms |
5076 KB |
Output is correct |
25 |
Correct |
4 ms |
5076 KB |
Output is correct |
26 |
Correct |
4 ms |
5016 KB |
Output is correct |
27 |
Correct |
3 ms |
5076 KB |
Output is correct |
28 |
Correct |
4 ms |
5076 KB |
Output is correct |
29 |
Correct |
5 ms |
5204 KB |
Output is correct |
30 |
Correct |
4 ms |
5148 KB |
Output is correct |
31 |
Correct |
4 ms |
5020 KB |
Output is correct |
32 |
Correct |
4 ms |
5076 KB |
Output is correct |
33 |
Correct |
4 ms |
5076 KB |
Output is correct |
34 |
Correct |
3 ms |
5076 KB |
Output is correct |
35 |
Correct |
3 ms |
5020 KB |
Output is correct |
36 |
Correct |
5 ms |
5072 KB |
Output is correct |
37 |
Correct |
3 ms |
5076 KB |
Output is correct |
38 |
Correct |
3 ms |
5076 KB |
Output is correct |
39 |
Correct |
4 ms |
5144 KB |
Output is correct |
40 |
Correct |
4 ms |
5076 KB |
Output is correct |
41 |
Correct |
4 ms |
5148 KB |
Output is correct |
42 |
Correct |
4 ms |
5076 KB |
Output is correct |
43 |
Correct |
3 ms |
5012 KB |
Output is correct |
44 |
Correct |
4 ms |
5076 KB |
Output is correct |
45 |
Correct |
5 ms |
5076 KB |
Output is correct |
46 |
Correct |
5 ms |
5076 KB |
Output is correct |
47 |
Correct |
5 ms |
5016 KB |
Output is correct |
48 |
Correct |
4 ms |
5076 KB |
Output is correct |
49 |
Correct |
4 ms |
5140 KB |
Output is correct |
50 |
Correct |
5 ms |
5012 KB |
Output is correct |
51 |
Correct |
4 ms |
5076 KB |
Output is correct |
52 |
Correct |
3 ms |
5076 KB |
Output is correct |
53 |
Correct |
4 ms |
5012 KB |
Output is correct |
54 |
Correct |
3 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 |
3 ms |
5204 KB |
Output is correct |
58 |
Correct |
3 ms |
5012 KB |
Output is correct |
59 |
Correct |
3 ms |
5076 KB |
Output is correct |
60 |
Correct |
4 ms |
5076 KB |
Output is correct |
61 |
Correct |
3 ms |
5076 KB |
Output is correct |
62 |
Correct |
4 ms |
5076 KB |
Output is correct |
63 |
Correct |
4 ms |
5076 KB |
Output is correct |
64 |
Correct |
137 ms |
14156 KB |
Output is correct |
65 |
Correct |
168 ms |
14264 KB |
Output is correct |
66 |
Correct |
119 ms |
14264 KB |
Output is correct |
67 |
Correct |
120 ms |
14352 KB |
Output is correct |
68 |
Correct |
124 ms |
14236 KB |
Output is correct |
69 |
Correct |
145 ms |
14152 KB |
Output is correct |
70 |
Correct |
137 ms |
14344 KB |
Output is correct |
71 |
Correct |
124 ms |
14172 KB |
Output is correct |
72 |
Correct |
125 ms |
14212 KB |
Output is correct |
73 |
Correct |
176 ms |
26788 KB |
Output is correct |
74 |
Correct |
188 ms |
26776 KB |
Output is correct |
75 |
Correct |
134 ms |
14064 KB |
Output is correct |
76 |
Correct |
125 ms |
14156 KB |
Output is correct |
77 |
Correct |
186 ms |
14112 KB |
Output is correct |
78 |
Correct |
153 ms |
14028 KB |
Output is correct |
79 |
Correct |
126 ms |
14096 KB |
Output is correct |
80 |
Correct |
124 ms |
14136 KB |
Output is correct |
81 |
Correct |
123 ms |
14480 KB |
Output is correct |
82 |
Correct |
136 ms |
14364 KB |
Output is correct |
83 |
Correct |
132 ms |
19432 KB |
Output is correct |
84 |
Correct |
141 ms |
21440 KB |
Output is correct |
85 |
Correct |
172 ms |
21068 KB |
Output is correct |
86 |
Correct |
142 ms |
15516 KB |
Output is correct |
87 |
Correct |
123 ms |
14976 KB |
Output is correct |
88 |
Correct |
133 ms |
15388 KB |
Output is correct |
89 |
Correct |
167 ms |
15524 KB |
Output is correct |
90 |
Correct |
119 ms |
15288 KB |
Output is correct |
91 |
Correct |
131 ms |
15520 KB |
Output is correct |
92 |
Correct |
115 ms |
15784 KB |
Output is correct |
93 |
Correct |
114 ms |
18148 KB |
Output is correct |
94 |
Correct |
157 ms |
19900 KB |
Output is correct |
95 |
Correct |
136 ms |
18624 KB |
Output is correct |
96 |
Correct |
127 ms |
16852 KB |
Output is correct |
97 |
Correct |
136 ms |
15308 KB |
Output is correct |
98 |
Correct |
118 ms |
14832 KB |
Output is correct |
99 |
Correct |
123 ms |
14612 KB |
Output is correct |
100 |
Correct |
143 ms |
17760 KB |
Output is correct |
101 |
Correct |
174 ms |
15708 KB |
Output is correct |
102 |
Correct |
116 ms |
14940 KB |
Output is correct |
103 |
Correct |
119 ms |
14848 KB |
Output is correct |
104 |
Correct |
110 ms |
14944 KB |
Output is correct |
105 |
Correct |
193 ms |
23580 KB |
Output is correct |
106 |
Correct |
90 ms |
14848 KB |
Output is correct |
107 |
Correct |
93 ms |
14776 KB |
Output is correct |
108 |
Correct |
163 ms |
27528 KB |
Output is correct |
109 |
Correct |
94 ms |
15020 KB |
Output is correct |
110 |
Correct |
170 ms |
27848 KB |
Output is correct |
111 |
Correct |
140 ms |
14112 KB |
Output is correct |