Submission #417199

# Submission time Handle Problem Language Result Execution time Memory
417199 2021-06-03T12:56:02 Z Knps4422 Power Plant (JOI20_power) C++14
100 / 100
310 ms 28672 KB
//#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];
int dp[nmax];

int rez;
void cm(int nod , int parent){
	int rs = (asd[nod] == '1');
	int rs2 = -(asd[nod] == '1');
	for(int i : g[nod]){
		if(i == parent)continue;
		cm(i,nod);
		rs2 += dp[i];
		rs = max(rs , dp[i] + (asd[nod] == '1'));
	}
	dp[nod] = rs2;
	if(asd[nod] == '1')dp[nod] = max(dp[nod],1);
	rez = max(rez , rs2);
	rez = max(rez , rs);
}

int main(){
	cin >> n;
	for(int i = 1; i < n; i++){
		int a, b;
		cin >> a >> b;
		g[a].pb(b);
		g[b].pb(a);
	}
	for(int i = 1; i <= n; i++){
		cin >> asd[i];
	}
	cm(1,0);
	cout << rez << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 5004 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 5004 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 5004 KB Output is correct
17 Correct 3 ms 5004 KB Output is correct
18 Correct 3 ms 4920 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 5008 KB Output is correct
21 Correct 3 ms 5008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 5004 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 5004 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 5004 KB Output is correct
17 Correct 3 ms 5004 KB Output is correct
18 Correct 3 ms 4920 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 5008 KB Output is correct
21 Correct 3 ms 5008 KB Output is correct
22 Correct 4 ms 5068 KB Output is correct
23 Correct 4 ms 5068 KB Output is correct
24 Correct 5 ms 5068 KB Output is correct
25 Correct 5 ms 5024 KB Output is correct
26 Correct 5 ms 5072 KB Output is correct
27 Correct 5 ms 5068 KB Output is correct
28 Correct 5 ms 5072 KB Output is correct
29 Correct 5 ms 5196 KB Output is correct
30 Correct 5 ms 5196 KB Output is correct
31 Correct 5 ms 5020 KB Output is correct
32 Correct 6 ms 5068 KB Output is correct
33 Correct 5 ms 5068 KB Output is correct
34 Correct 5 ms 5068 KB Output is correct
35 Correct 5 ms 5068 KB Output is correct
36 Correct 5 ms 5048 KB Output is correct
37 Correct 4 ms 5068 KB Output is correct
38 Correct 5 ms 5024 KB Output is correct
39 Correct 5 ms 5144 KB Output is correct
40 Correct 5 ms 5144 KB Output is correct
41 Correct 5 ms 5068 KB Output is correct
42 Correct 5 ms 5068 KB Output is correct
43 Correct 5 ms 5068 KB Output is correct
44 Correct 5 ms 5068 KB Output is correct
45 Correct 5 ms 5068 KB Output is correct
46 Correct 4 ms 5068 KB Output is correct
47 Correct 5 ms 5024 KB Output is correct
48 Correct 5 ms 5068 KB Output is correct
49 Correct 4 ms 5188 KB Output is correct
50 Correct 5 ms 5068 KB Output is correct
51 Correct 5 ms 5068 KB Output is correct
52 Correct 5 ms 5068 KB Output is correct
53 Correct 5 ms 5116 KB Output is correct
54 Correct 5 ms 5068 KB Output is correct
55 Correct 4 ms 5068 KB Output is correct
56 Correct 5 ms 5100 KB Output is correct
57 Correct 5 ms 5148 KB Output is correct
58 Correct 4 ms 5068 KB Output is correct
59 Correct 7 ms 5068 KB Output is correct
60 Correct 5 ms 5068 KB Output is correct
61 Correct 5 ms 5068 KB Output is correct
62 Correct 5 ms 5196 KB Output is correct
63 Correct 5 ms 5068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 5004 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 5004 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 5004 KB Output is correct
17 Correct 3 ms 5004 KB Output is correct
18 Correct 3 ms 4920 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 5008 KB Output is correct
21 Correct 3 ms 5008 KB Output is correct
22 Correct 4 ms 5068 KB Output is correct
23 Correct 4 ms 5068 KB Output is correct
24 Correct 5 ms 5068 KB Output is correct
25 Correct 5 ms 5024 KB Output is correct
26 Correct 5 ms 5072 KB Output is correct
27 Correct 5 ms 5068 KB Output is correct
28 Correct 5 ms 5072 KB Output is correct
29 Correct 5 ms 5196 KB Output is correct
30 Correct 5 ms 5196 KB Output is correct
31 Correct 5 ms 5020 KB Output is correct
32 Correct 6 ms 5068 KB Output is correct
33 Correct 5 ms 5068 KB Output is correct
34 Correct 5 ms 5068 KB Output is correct
35 Correct 5 ms 5068 KB Output is correct
36 Correct 5 ms 5048 KB Output is correct
37 Correct 4 ms 5068 KB Output is correct
38 Correct 5 ms 5024 KB Output is correct
39 Correct 5 ms 5144 KB Output is correct
40 Correct 5 ms 5144 KB Output is correct
41 Correct 5 ms 5068 KB Output is correct
42 Correct 5 ms 5068 KB Output is correct
43 Correct 5 ms 5068 KB Output is correct
44 Correct 5 ms 5068 KB Output is correct
45 Correct 5 ms 5068 KB Output is correct
46 Correct 4 ms 5068 KB Output is correct
47 Correct 5 ms 5024 KB Output is correct
48 Correct 5 ms 5068 KB Output is correct
49 Correct 4 ms 5188 KB Output is correct
50 Correct 5 ms 5068 KB Output is correct
51 Correct 5 ms 5068 KB Output is correct
52 Correct 5 ms 5068 KB Output is correct
53 Correct 5 ms 5116 KB Output is correct
54 Correct 5 ms 5068 KB Output is correct
55 Correct 4 ms 5068 KB Output is correct
56 Correct 5 ms 5100 KB Output is correct
57 Correct 5 ms 5148 KB Output is correct
58 Correct 4 ms 5068 KB Output is correct
59 Correct 7 ms 5068 KB Output is correct
60 Correct 5 ms 5068 KB Output is correct
61 Correct 5 ms 5068 KB Output is correct
62 Correct 5 ms 5196 KB Output is correct
63 Correct 5 ms 5068 KB Output is correct
64 Correct 246 ms 14668 KB Output is correct
65 Correct 249 ms 14532 KB Output is correct
66 Correct 248 ms 14532 KB Output is correct
67 Correct 244 ms 14648 KB Output is correct
68 Correct 277 ms 14632 KB Output is correct
69 Correct 246 ms 14536 KB Output is correct
70 Correct 254 ms 14628 KB Output is correct
71 Correct 245 ms 14640 KB Output is correct
72 Correct 258 ms 14600 KB Output is correct
73 Correct 283 ms 27196 KB Output is correct
74 Correct 292 ms 27084 KB Output is correct
75 Correct 256 ms 14516 KB Output is correct
76 Correct 245 ms 14464 KB Output is correct
77 Correct 246 ms 14476 KB Output is correct
78 Correct 257 ms 14656 KB Output is correct
79 Correct 272 ms 14400 KB Output is correct
80 Correct 266 ms 14416 KB Output is correct
81 Correct 237 ms 14920 KB Output is correct
82 Correct 233 ms 15144 KB Output is correct
83 Correct 264 ms 20164 KB Output is correct
84 Correct 289 ms 22236 KB Output is correct
85 Correct 265 ms 22104 KB Output is correct
86 Correct 264 ms 16480 KB Output is correct
87 Correct 270 ms 15812 KB Output is correct
88 Correct 287 ms 16160 KB Output is correct
89 Correct 276 ms 16476 KB Output is correct
90 Correct 310 ms 16040 KB Output is correct
91 Correct 288 ms 16300 KB Output is correct
92 Correct 303 ms 16608 KB Output is correct
93 Correct 244 ms 19008 KB Output is correct
94 Correct 254 ms 20572 KB Output is correct
95 Correct 266 ms 19432 KB Output is correct
96 Correct 263 ms 17548 KB Output is correct
97 Correct 276 ms 16088 KB Output is correct
98 Correct 281 ms 15584 KB Output is correct
99 Correct 288 ms 15316 KB Output is correct
100 Correct 269 ms 18524 KB Output is correct
101 Correct 250 ms 16552 KB Output is correct
102 Correct 265 ms 15812 KB Output is correct
103 Correct 270 ms 15524 KB Output is correct
104 Correct 218 ms 15800 KB Output is correct
105 Correct 284 ms 24484 KB Output is correct
106 Correct 195 ms 15548 KB Output is correct
107 Correct 191 ms 15620 KB Output is correct
108 Correct 264 ms 28356 KB Output is correct
109 Correct 197 ms 15844 KB Output is correct
110 Correct 268 ms 28672 KB Output is correct
111 Correct 240 ms 14824 KB Output is correct