//#pragma optimization_level 3
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordset;
*/
#define fr first
#define sc second
#define vec vector
#define pb push_back
#define pii pair<int, int>
#define forn(x,y) for(int x = 1 ; x <= (int)y ; ++x)
#define all(x) (x).begin(),(x).end()
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef pair<ll,ll> pll;
typedef complex<int> point;
const int nmax = 200005;
const ll linf = 1e18;
const ll mod = 998244353;
const int inf = 1e9+10;
const int sq = 5000;
int n;
char asd[nmax];
int viz[nmax];
vec < int > g[nmax] , ng[nmax];
pii edges[2*nmax];
int done[2*nmax];
int dp[2*nmax];
int compute_dp(int ed){
int nod1 = edges[ed].fr , nod2 = edges[ed].sc;
if(done[ed] == 1){
//cout << "dp: " << nod1 << ' '<< nod2 << ' '<< dp[{nod1,nod2}].fr << '\n';
return dp[ed];
}
int rs = -(asd[nod2] == '1') , rs2 = (asd[nod2] == '1');
for(int i : g[nod2]){
if(edges[i].sc != nod1){
rs += compute_dp(i);
}
}
dp[ed] = max(rs,rs2);
done[ed] = 1;
//cout << "dp: " << nod1 << ' '<< nod2 << ' '<< max(rs,rs2) << '\n';
return dp[ed];
}
int main(){
cin >> n;
for(int i = 1; i < n; i++){
int a, b;
cin >> a >> b;
g[a].pb(i);
g[b].pb(n+i);
edges[i] = {a,b};
edges[i+n] = {b,a};
}
int cnt = 0;
for(int i = 1; i <= n; i++){
cin >> asd[i];
cnt += (asd[i] == '1');
}
int rez;
if(cnt >= 2){
rez = 2;
}else{
rez = 1;
}
for(int i = 1; i <= n; i++){
int rs;
//cout << "COMPUTE " << i << '\n';
if(asd[i] == '1')rs = -1;
else rs = 0;
//cout << rs << '\n';
for(int ed : g[i]){
int j = edges[ed].sc;
rs += compute_dp(ed);
}
//cout << i << ' ' << rs << '\n';
rez = max(rez,rs);
}
cout << rez << '\n';
}
Compilation message
power.cpp: In function 'int main()':
power.cpp:86:8: warning: unused variable 'j' [-Wunused-variable]
86 | int j = edges[ed].sc;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9676 KB |
Output is correct |
2 |
Correct |
6 ms |
9608 KB |
Output is correct |
3 |
Correct |
7 ms |
9676 KB |
Output is correct |
4 |
Correct |
6 ms |
9624 KB |
Output is correct |
5 |
Correct |
6 ms |
9784 KB |
Output is correct |
6 |
Correct |
7 ms |
9648 KB |
Output is correct |
7 |
Correct |
7 ms |
9676 KB |
Output is correct |
8 |
Correct |
7 ms |
9704 KB |
Output is correct |
9 |
Correct |
6 ms |
9676 KB |
Output is correct |
10 |
Correct |
6 ms |
9676 KB |
Output is correct |
11 |
Correct |
6 ms |
9676 KB |
Output is correct |
12 |
Correct |
6 ms |
9700 KB |
Output is correct |
13 |
Correct |
6 ms |
9692 KB |
Output is correct |
14 |
Correct |
6 ms |
9700 KB |
Output is correct |
15 |
Correct |
6 ms |
9676 KB |
Output is correct |
16 |
Correct |
6 ms |
9676 KB |
Output is correct |
17 |
Correct |
6 ms |
9700 KB |
Output is correct |
18 |
Correct |
6 ms |
9700 KB |
Output is correct |
19 |
Correct |
7 ms |
9676 KB |
Output is correct |
20 |
Correct |
6 ms |
9676 KB |
Output is correct |
21 |
Correct |
6 ms |
9676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9676 KB |
Output is correct |
2 |
Correct |
6 ms |
9608 KB |
Output is correct |
3 |
Correct |
7 ms |
9676 KB |
Output is correct |
4 |
Correct |
6 ms |
9624 KB |
Output is correct |
5 |
Correct |
6 ms |
9784 KB |
Output is correct |
6 |
Correct |
7 ms |
9648 KB |
Output is correct |
7 |
Correct |
7 ms |
9676 KB |
Output is correct |
8 |
Correct |
7 ms |
9704 KB |
Output is correct |
9 |
Correct |
6 ms |
9676 KB |
Output is correct |
10 |
Correct |
6 ms |
9676 KB |
Output is correct |
11 |
Correct |
6 ms |
9676 KB |
Output is correct |
12 |
Correct |
6 ms |
9700 KB |
Output is correct |
13 |
Correct |
6 ms |
9692 KB |
Output is correct |
14 |
Correct |
6 ms |
9700 KB |
Output is correct |
15 |
Correct |
6 ms |
9676 KB |
Output is correct |
16 |
Correct |
6 ms |
9676 KB |
Output is correct |
17 |
Correct |
6 ms |
9700 KB |
Output is correct |
18 |
Correct |
6 ms |
9700 KB |
Output is correct |
19 |
Correct |
7 ms |
9676 KB |
Output is correct |
20 |
Correct |
6 ms |
9676 KB |
Output is correct |
21 |
Correct |
6 ms |
9676 KB |
Output is correct |
22 |
Correct |
9 ms |
9804 KB |
Output is correct |
23 |
Correct |
8 ms |
9804 KB |
Output is correct |
24 |
Correct |
8 ms |
9804 KB |
Output is correct |
25 |
Correct |
8 ms |
9804 KB |
Output is correct |
26 |
Correct |
8 ms |
9804 KB |
Output is correct |
27 |
Correct |
8 ms |
9804 KB |
Output is correct |
28 |
Correct |
8 ms |
9804 KB |
Output is correct |
29 |
Correct |
8 ms |
9972 KB |
Output is correct |
30 |
Correct |
8 ms |
9848 KB |
Output is correct |
31 |
Correct |
8 ms |
9804 KB |
Output is correct |
32 |
Correct |
8 ms |
9804 KB |
Output is correct |
33 |
Correct |
8 ms |
9804 KB |
Output is correct |
34 |
Correct |
8 ms |
9804 KB |
Output is correct |
35 |
Correct |
8 ms |
9804 KB |
Output is correct |
36 |
Correct |
8 ms |
9804 KB |
Output is correct |
37 |
Correct |
14 ms |
9804 KB |
Output is correct |
38 |
Correct |
10 ms |
9804 KB |
Output is correct |
39 |
Correct |
8 ms |
9932 KB |
Output is correct |
40 |
Correct |
8 ms |
9804 KB |
Output is correct |
41 |
Correct |
8 ms |
9932 KB |
Output is correct |
42 |
Correct |
8 ms |
9804 KB |
Output is correct |
43 |
Correct |
8 ms |
9804 KB |
Output is correct |
44 |
Correct |
9 ms |
9804 KB |
Output is correct |
45 |
Correct |
8 ms |
9804 KB |
Output is correct |
46 |
Correct |
9 ms |
9804 KB |
Output is correct |
47 |
Correct |
8 ms |
9804 KB |
Output is correct |
48 |
Correct |
15 ms |
9932 KB |
Output is correct |
49 |
Correct |
11 ms |
9840 KB |
Output is correct |
50 |
Correct |
10 ms |
9836 KB |
Output is correct |
51 |
Correct |
9 ms |
9804 KB |
Output is correct |
52 |
Correct |
8 ms |
9776 KB |
Output is correct |
53 |
Correct |
10 ms |
9844 KB |
Output is correct |
54 |
Correct |
8 ms |
9844 KB |
Output is correct |
55 |
Correct |
8 ms |
9804 KB |
Output is correct |
56 |
Correct |
36 ms |
9804 KB |
Output is correct |
57 |
Correct |
8 ms |
9932 KB |
Output is correct |
58 |
Correct |
32 ms |
9808 KB |
Output is correct |
59 |
Correct |
32 ms |
9804 KB |
Output is correct |
60 |
Correct |
9 ms |
9840 KB |
Output is correct |
61 |
Correct |
34 ms |
9860 KB |
Output is correct |
62 |
Correct |
8 ms |
9932 KB |
Output is correct |
63 |
Correct |
8 ms |
9804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9676 KB |
Output is correct |
2 |
Correct |
6 ms |
9608 KB |
Output is correct |
3 |
Correct |
7 ms |
9676 KB |
Output is correct |
4 |
Correct |
6 ms |
9624 KB |
Output is correct |
5 |
Correct |
6 ms |
9784 KB |
Output is correct |
6 |
Correct |
7 ms |
9648 KB |
Output is correct |
7 |
Correct |
7 ms |
9676 KB |
Output is correct |
8 |
Correct |
7 ms |
9704 KB |
Output is correct |
9 |
Correct |
6 ms |
9676 KB |
Output is correct |
10 |
Correct |
6 ms |
9676 KB |
Output is correct |
11 |
Correct |
6 ms |
9676 KB |
Output is correct |
12 |
Correct |
6 ms |
9700 KB |
Output is correct |
13 |
Correct |
6 ms |
9692 KB |
Output is correct |
14 |
Correct |
6 ms |
9700 KB |
Output is correct |
15 |
Correct |
6 ms |
9676 KB |
Output is correct |
16 |
Correct |
6 ms |
9676 KB |
Output is correct |
17 |
Correct |
6 ms |
9700 KB |
Output is correct |
18 |
Correct |
6 ms |
9700 KB |
Output is correct |
19 |
Correct |
7 ms |
9676 KB |
Output is correct |
20 |
Correct |
6 ms |
9676 KB |
Output is correct |
21 |
Correct |
6 ms |
9676 KB |
Output is correct |
22 |
Correct |
9 ms |
9804 KB |
Output is correct |
23 |
Correct |
8 ms |
9804 KB |
Output is correct |
24 |
Correct |
8 ms |
9804 KB |
Output is correct |
25 |
Correct |
8 ms |
9804 KB |
Output is correct |
26 |
Correct |
8 ms |
9804 KB |
Output is correct |
27 |
Correct |
8 ms |
9804 KB |
Output is correct |
28 |
Correct |
8 ms |
9804 KB |
Output is correct |
29 |
Correct |
8 ms |
9972 KB |
Output is correct |
30 |
Correct |
8 ms |
9848 KB |
Output is correct |
31 |
Correct |
8 ms |
9804 KB |
Output is correct |
32 |
Correct |
8 ms |
9804 KB |
Output is correct |
33 |
Correct |
8 ms |
9804 KB |
Output is correct |
34 |
Correct |
8 ms |
9804 KB |
Output is correct |
35 |
Correct |
8 ms |
9804 KB |
Output is correct |
36 |
Correct |
8 ms |
9804 KB |
Output is correct |
37 |
Correct |
14 ms |
9804 KB |
Output is correct |
38 |
Correct |
10 ms |
9804 KB |
Output is correct |
39 |
Correct |
8 ms |
9932 KB |
Output is correct |
40 |
Correct |
8 ms |
9804 KB |
Output is correct |
41 |
Correct |
8 ms |
9932 KB |
Output is correct |
42 |
Correct |
8 ms |
9804 KB |
Output is correct |
43 |
Correct |
8 ms |
9804 KB |
Output is correct |
44 |
Correct |
9 ms |
9804 KB |
Output is correct |
45 |
Correct |
8 ms |
9804 KB |
Output is correct |
46 |
Correct |
9 ms |
9804 KB |
Output is correct |
47 |
Correct |
8 ms |
9804 KB |
Output is correct |
48 |
Correct |
15 ms |
9932 KB |
Output is correct |
49 |
Correct |
11 ms |
9840 KB |
Output is correct |
50 |
Correct |
10 ms |
9836 KB |
Output is correct |
51 |
Correct |
9 ms |
9804 KB |
Output is correct |
52 |
Correct |
8 ms |
9776 KB |
Output is correct |
53 |
Correct |
10 ms |
9844 KB |
Output is correct |
54 |
Correct |
8 ms |
9844 KB |
Output is correct |
55 |
Correct |
8 ms |
9804 KB |
Output is correct |
56 |
Correct |
36 ms |
9804 KB |
Output is correct |
57 |
Correct |
8 ms |
9932 KB |
Output is correct |
58 |
Correct |
32 ms |
9808 KB |
Output is correct |
59 |
Correct |
32 ms |
9804 KB |
Output is correct |
60 |
Correct |
9 ms |
9840 KB |
Output is correct |
61 |
Correct |
34 ms |
9860 KB |
Output is correct |
62 |
Correct |
8 ms |
9932 KB |
Output is correct |
63 |
Correct |
8 ms |
9804 KB |
Output is correct |
64 |
Correct |
486 ms |
23592 KB |
Output is correct |
65 |
Correct |
439 ms |
23404 KB |
Output is correct |
66 |
Correct |
459 ms |
23468 KB |
Output is correct |
67 |
Correct |
479 ms |
23364 KB |
Output is correct |
68 |
Correct |
473 ms |
23404 KB |
Output is correct |
69 |
Correct |
431 ms |
23396 KB |
Output is correct |
70 |
Correct |
502 ms |
23400 KB |
Output is correct |
71 |
Correct |
435 ms |
23292 KB |
Output is correct |
72 |
Correct |
446 ms |
23336 KB |
Output is correct |
73 |
Correct |
499 ms |
36020 KB |
Output is correct |
74 |
Correct |
438 ms |
35924 KB |
Output is correct |
75 |
Correct |
425 ms |
23240 KB |
Output is correct |
76 |
Correct |
430 ms |
23236 KB |
Output is correct |
77 |
Correct |
416 ms |
23288 KB |
Output is correct |
78 |
Correct |
425 ms |
23328 KB |
Output is correct |
79 |
Correct |
411 ms |
23236 KB |
Output is correct |
80 |
Correct |
464 ms |
23280 KB |
Output is correct |
81 |
Execution timed out |
1585 ms |
23616 KB |
Time limit exceeded |
82 |
Halted |
0 ms |
0 KB |
- |