Submission #293364

# Submission time Handle Problem Language Result Execution time Memory
293364 2020-09-08T00:44:46 Z Gajowy Power Plant (JOI20_power) C++14
100 / 100
258 ms 28856 KB
#pragma GCC optimize("Ofast")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define e1 first
#define e2 second
#define int int_fast32_t
#define uint uint_fast64_t
#define ll int_fast64_t
#define ull uint_fast64_t
#define int16 int_fast16_t
#define uint16 uint_fast16_t
#define int32 int_fast32_t
#define uint32 uint_fast32_t
#define int64 int_fast64_t
#define uint64 uint_fast64_t
#define ld long double
#define float long double
#define size(x) (int)x.size()
#define satori int testCases; cin>>testCases; while(testCases--)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define all(r) begin(r),end(r)
#define rall(r) rbegin(r),rend(r)
#define time chrono::high_resolution_clock().now().time_since_epoch().count()
#define elapsed(__begin,__end) (__end-__begin)/CLOCKS_PER_SEC
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
float pi=3.14159265358979323846;

const int MAXN=2e5+10;

int dp[MAXN],dp2[MAXN],pp[MAXN],pr[MAXN];
vector<int> g[MAXN];
string s;

void dfs(int u,int p)
{
	pr[u]=p;
	dp[u]=pp[u];
	int sm=-pp[u];
	for(auto v:g[u])
		if(v!=p)
			dfs(v,u),sm+=dp[v];
	dp[u]=max(dp[u],sm);
}

void dfs2(int u,int p)
{
	int sm=dp2[u];
	for(auto v:g[u])
		if(v!=p)
			sm+=dp[v];
	for(auto v:g[u])
		if(v!=p)
			dp2[v]=max(pp[u],sm-dp[v]-pp[u]),dfs2(v,u);
}

int32_t main()
{
	fastio;
	int n,u,v,res=0;
	cin>>n;
	for(int i=1;i<n;i++)
		cin>>u>>v,g[u].eb(v),g[v].eb(u);
	cin>>s;
	for(int i=0;i<n;i++)
		pp[i+1]=(int)(s[i]-'0');
	dfs(1,0);
	dfs2(1,0);
	for(int i=1;i<=n;i++)
	{
		res=max(res,dp[i]+dp2[i]);
		for(auto vv:g[i])
			if(vv!=pr[i])
				res=max(res,pp[i]+dp[vv]);
	}
	cout<<res<<'\n';
}

Compilation message

power.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    2 | #pragma GCC optimization ("O3")
      | 
power.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      |
# 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 4 ms 5120 KB Output is correct
12 Correct 5 ms 4992 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Correct 4 ms 4992 KB Output is correct
15 Correct 4 ms 4992 KB Output is correct
16 Correct 4 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 4 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 4 ms 5120 KB Output is correct
12 Correct 5 ms 4992 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Correct 4 ms 4992 KB Output is correct
15 Correct 4 ms 4992 KB Output is correct
16 Correct 4 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 4 ms 4992 KB Output is correct
21 Correct 4 ms 4992 KB Output is correct
22 Correct 6 ms 5248 KB Output is correct
23 Correct 5 ms 5152 KB Output is correct
24 Correct 5 ms 5248 KB Output is correct
25 Correct 5 ms 5248 KB Output is correct
26 Correct 5 ms 5248 KB Output is correct
27 Correct 5 ms 5248 KB Output is correct
28 Correct 5 ms 5248 KB Output is correct
29 Correct 5 ms 5248 KB Output is correct
30 Correct 4 ms 5248 KB Output is correct
31 Correct 5 ms 5248 KB Output is correct
32 Correct 6 ms 5248 KB Output is correct
33 Correct 5 ms 5152 KB Output is correct
34 Correct 4 ms 5248 KB Output is correct
35 Correct 5 ms 5248 KB Output is correct
36 Correct 4 ms 5248 KB Output is correct
37 Correct 4 ms 5248 KB Output is correct
38 Correct 5 ms 5248 KB Output is correct
39 Correct 5 ms 5248 KB Output is correct
40 Correct 5 ms 5248 KB Output is correct
41 Correct 5 ms 5248 KB Output is correct
42 Correct 5 ms 5248 KB Output is correct
43 Correct 5 ms 5248 KB Output is correct
44 Correct 5 ms 5248 KB Output is correct
45 Correct 5 ms 5248 KB Output is correct
46 Correct 5 ms 5248 KB Output is correct
47 Correct 5 ms 5248 KB Output is correct
48 Correct 4 ms 5248 KB Output is correct
49 Correct 5 ms 5248 KB Output is correct
50 Correct 4 ms 5248 KB Output is correct
51 Correct 4 ms 5248 KB Output is correct
52 Correct 5 ms 5248 KB Output is correct
53 Correct 5 ms 5248 KB Output is correct
54 Correct 5 ms 5248 KB Output is correct
55 Correct 6 ms 5248 KB Output is correct
56 Correct 4 ms 5248 KB Output is correct
57 Correct 5 ms 5352 KB Output is correct
58 Correct 4 ms 5248 KB Output is correct
59 Correct 4 ms 5248 KB Output is correct
60 Correct 5 ms 5248 KB Output is correct
61 Correct 4 ms 5248 KB Output is correct
62 Correct 5 ms 5248 KB Output is correct
63 Correct 4 ms 5248 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 4 ms 5120 KB Output is correct
12 Correct 5 ms 4992 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Correct 4 ms 4992 KB Output is correct
15 Correct 4 ms 4992 KB Output is correct
16 Correct 4 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 4 ms 4992 KB Output is correct
21 Correct 4 ms 4992 KB Output is correct
22 Correct 6 ms 5248 KB Output is correct
23 Correct 5 ms 5152 KB Output is correct
24 Correct 5 ms 5248 KB Output is correct
25 Correct 5 ms 5248 KB Output is correct
26 Correct 5 ms 5248 KB Output is correct
27 Correct 5 ms 5248 KB Output is correct
28 Correct 5 ms 5248 KB Output is correct
29 Correct 5 ms 5248 KB Output is correct
30 Correct 4 ms 5248 KB Output is correct
31 Correct 5 ms 5248 KB Output is correct
32 Correct 6 ms 5248 KB Output is correct
33 Correct 5 ms 5152 KB Output is correct
34 Correct 4 ms 5248 KB Output is correct
35 Correct 5 ms 5248 KB Output is correct
36 Correct 4 ms 5248 KB Output is correct
37 Correct 4 ms 5248 KB Output is correct
38 Correct 5 ms 5248 KB Output is correct
39 Correct 5 ms 5248 KB Output is correct
40 Correct 5 ms 5248 KB Output is correct
41 Correct 5 ms 5248 KB Output is correct
42 Correct 5 ms 5248 KB Output is correct
43 Correct 5 ms 5248 KB Output is correct
44 Correct 5 ms 5248 KB Output is correct
45 Correct 5 ms 5248 KB Output is correct
46 Correct 5 ms 5248 KB Output is correct
47 Correct 5 ms 5248 KB Output is correct
48 Correct 4 ms 5248 KB Output is correct
49 Correct 5 ms 5248 KB Output is correct
50 Correct 4 ms 5248 KB Output is correct
51 Correct 4 ms 5248 KB Output is correct
52 Correct 5 ms 5248 KB Output is correct
53 Correct 5 ms 5248 KB Output is correct
54 Correct 5 ms 5248 KB Output is correct
55 Correct 6 ms 5248 KB Output is correct
56 Correct 4 ms 5248 KB Output is correct
57 Correct 5 ms 5352 KB Output is correct
58 Correct 4 ms 5248 KB Output is correct
59 Correct 4 ms 5248 KB Output is correct
60 Correct 5 ms 5248 KB Output is correct
61 Correct 4 ms 5248 KB Output is correct
62 Correct 5 ms 5248 KB Output is correct
63 Correct 4 ms 5248 KB Output is correct
64 Correct 221 ms 18996 KB Output is correct
65 Correct 219 ms 18996 KB Output is correct
66 Correct 219 ms 18984 KB Output is correct
67 Correct 216 ms 18996 KB Output is correct
68 Correct 216 ms 18920 KB Output is correct
69 Correct 231 ms 18996 KB Output is correct
70 Correct 216 ms 19016 KB Output is correct
71 Correct 236 ms 19016 KB Output is correct
72 Correct 218 ms 18996 KB Output is correct
73 Correct 258 ms 28088 KB Output is correct
74 Correct 254 ms 27960 KB Output is correct
75 Correct 214 ms 20148 KB Output is correct
76 Correct 226 ms 20204 KB Output is correct
77 Correct 227 ms 18992 KB Output is correct
78 Correct 228 ms 18996 KB Output is correct
79 Correct 229 ms 19004 KB Output is correct
80 Correct 227 ms 18996 KB Output is correct
81 Correct 170 ms 19052 KB Output is correct
82 Correct 202 ms 19180 KB Output is correct
83 Correct 232 ms 22972 KB Output is correct
84 Correct 236 ms 24776 KB Output is correct
85 Correct 250 ms 24516 KB Output is correct
86 Correct 224 ms 20024 KB Output is correct
87 Correct 219 ms 19508 KB Output is correct
88 Correct 201 ms 19700 KB Output is correct
89 Correct 199 ms 19780 KB Output is correct
90 Correct 201 ms 19612 KB Output is correct
91 Correct 204 ms 19868 KB Output is correct
92 Correct 204 ms 20136 KB Output is correct
93 Correct 201 ms 21744 KB Output is correct
94 Correct 185 ms 23280 KB Output is correct
95 Correct 191 ms 22120 KB Output is correct
96 Correct 205 ms 20536 KB Output is correct
97 Correct 198 ms 19420 KB Output is correct
98 Correct 207 ms 19176 KB Output is correct
99 Correct 225 ms 19048 KB Output is correct
100 Correct 197 ms 21412 KB Output is correct
101 Correct 197 ms 19636 KB Output is correct
102 Correct 211 ms 19208 KB Output is correct
103 Correct 212 ms 19288 KB Output is correct
104 Correct 123 ms 19556 KB Output is correct
105 Correct 251 ms 25528 KB Output is correct
106 Correct 114 ms 19560 KB Output is correct
107 Correct 110 ms 19556 KB Output is correct
108 Correct 249 ms 28600 KB Output is correct
109 Correct 112 ms 19556 KB Output is correct
110 Correct 246 ms 28856 KB Output is correct
111 Correct 189 ms 19088 KB Output is correct