Submission #955650

# Submission time Handle Problem Language Result Execution time Memory
955650 2024-03-31T08:52:51 Z thunopro Power Plant (JOI20_power) C++14
100 / 100
144 ms 28388 KB
#include<bits/stdc++.h>
using namespace std ; 
#define maxn 200009 
#define ll long long 
#define fi first 
#define se second 
#define pb push_back 
#define left id<<1
#define right id<<1|1 
#define _lower(x) lower_bound(v.begin(),v.end(),x)-v.begin()+1 
#define TIME (1.0*clock()/TIME_PERS_SEC) 
#define re exit(0); 

const int mod = 1e9+7 ; 
const int INF = 1e9 ; 

typedef vector<int> vi ; 
typedef pair<int,int> pii ; 
typedef vector<pii> vii ; 

void add ( int &a , int b ) 
{
	a += b ; 
	if ( a >= mod ) a -= mod ; 
	if ( a < 0 ) a += mod ; 
}

template < typename T > void chkmin ( T &a , T b ) { if ( a > b ) a = b ;} 
template < typename T > void chkmax ( T &a , T b ) { if ( a < b ) a = b ;} 

void rf () 
{
	freopen ("bai1.inp","r",stdin) ; 
}

mt19937 rng (time(0)) ; 

int _pow ( int a , int n ) 
{
	if ( n == 0 ) return 1 ; 
	int res = _pow (a,n/2) ; 
	if ( n % 2 ) return 1ll*res*res%mod*a%mod ; 
	else return 1ll*res*res%mod ; 
}

int n ; 
vi adjList [maxn] ; 
int ON [maxn] ; 
int dp [maxn] , res = 0 ; 
void dfs ( int u , int par = -1 ) 
{
	dp [u] = ON [u] ; 
	int sum = 0 , Max = 0 ; 
	for ( auto v : adjList [u] ) 
	{
		if ( v == par ) continue ; 
		dfs (v,u) ; 
		sum += dp [v] ; 
		chkmax (Max,dp[v]) ;
	}
	chkmax (dp[u],sum-ON[u]) ; 
	chkmax (res,dp[u]) ; 
	chkmax (res,Max+ON[u]) ; 
}
int main ()
{
	ios_base::sync_with_stdio(0); 
	cin.tie(0);cout.tie(0); 
//	rf () ; 
	cin >> n ; 
	for ( int i = 1 ; i < n ; i ++ ) 
	{
		int u , v ; cin >> u >> v ; 
		adjList [u] . pb (v) ; 
		adjList [v] . pb (u) ; 
	}
	for ( int i = 1 ; i <= n ; i ++ ) 
	{
		char c ; cin >> c ; 
		ON [i] = c - '0' ; 
	}
	dfs (1) ; 
	cout << res ; 
}

Compilation message

power.cpp: In function 'void rf()':
power.cpp:33:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |  freopen ("bai1.inp","r",stdin) ;
      |  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 3 ms 6328 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6336 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6332 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 2 ms 6548 KB Output is correct
18 Correct 3 ms 6552 KB Output is correct
19 Correct 2 ms 6488 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 3 ms 6328 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6336 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6332 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 2 ms 6548 KB Output is correct
18 Correct 3 ms 6552 KB Output is correct
19 Correct 2 ms 6488 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 3 ms 6492 KB Output is correct
23 Correct 3 ms 6596 KB Output is correct
24 Correct 3 ms 6492 KB Output is correct
25 Correct 3 ms 6492 KB Output is correct
26 Correct 3 ms 6492 KB Output is correct
27 Correct 3 ms 6492 KB Output is correct
28 Correct 2 ms 6492 KB Output is correct
29 Correct 3 ms 6748 KB Output is correct
30 Correct 3 ms 6560 KB Output is correct
31 Correct 2 ms 6492 KB Output is correct
32 Correct 3 ms 6492 KB Output is correct
33 Correct 3 ms 6492 KB Output is correct
34 Correct 2 ms 6492 KB Output is correct
35 Correct 3 ms 6492 KB Output is correct
36 Correct 2 ms 6492 KB Output is correct
37 Correct 3 ms 6492 KB Output is correct
38 Correct 2 ms 6492 KB Output is correct
39 Correct 2 ms 6492 KB Output is correct
40 Correct 2 ms 6492 KB Output is correct
41 Correct 2 ms 6488 KB Output is correct
42 Correct 2 ms 6492 KB Output is correct
43 Correct 3 ms 6492 KB Output is correct
44 Correct 3 ms 6488 KB Output is correct
45 Correct 3 ms 6488 KB Output is correct
46 Correct 2 ms 6492 KB Output is correct
47 Correct 2 ms 6632 KB Output is correct
48 Correct 2 ms 6688 KB Output is correct
49 Correct 3 ms 6560 KB Output is correct
50 Correct 2 ms 6636 KB Output is correct
51 Correct 2 ms 6492 KB Output is correct
52 Correct 2 ms 6492 KB Output is correct
53 Correct 2 ms 6492 KB Output is correct
54 Correct 3 ms 6492 KB Output is correct
55 Correct 2 ms 6492 KB Output is correct
56 Correct 2 ms 6492 KB Output is correct
57 Correct 3 ms 6748 KB Output is correct
58 Correct 2 ms 6648 KB Output is correct
59 Correct 2 ms 6492 KB Output is correct
60 Correct 2 ms 6492 KB Output is correct
61 Correct 2 ms 6492 KB Output is correct
62 Correct 2 ms 6492 KB Output is correct
63 Correct 2 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 3 ms 6328 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6336 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6332 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 2 ms 6548 KB Output is correct
18 Correct 3 ms 6552 KB Output is correct
19 Correct 2 ms 6488 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 3 ms 6492 KB Output is correct
23 Correct 3 ms 6596 KB Output is correct
24 Correct 3 ms 6492 KB Output is correct
25 Correct 3 ms 6492 KB Output is correct
26 Correct 3 ms 6492 KB Output is correct
27 Correct 3 ms 6492 KB Output is correct
28 Correct 2 ms 6492 KB Output is correct
29 Correct 3 ms 6748 KB Output is correct
30 Correct 3 ms 6560 KB Output is correct
31 Correct 2 ms 6492 KB Output is correct
32 Correct 3 ms 6492 KB Output is correct
33 Correct 3 ms 6492 KB Output is correct
34 Correct 2 ms 6492 KB Output is correct
35 Correct 3 ms 6492 KB Output is correct
36 Correct 2 ms 6492 KB Output is correct
37 Correct 3 ms 6492 KB Output is correct
38 Correct 2 ms 6492 KB Output is correct
39 Correct 2 ms 6492 KB Output is correct
40 Correct 2 ms 6492 KB Output is correct
41 Correct 2 ms 6488 KB Output is correct
42 Correct 2 ms 6492 KB Output is correct
43 Correct 3 ms 6492 KB Output is correct
44 Correct 3 ms 6488 KB Output is correct
45 Correct 3 ms 6488 KB Output is correct
46 Correct 2 ms 6492 KB Output is correct
47 Correct 2 ms 6632 KB Output is correct
48 Correct 2 ms 6688 KB Output is correct
49 Correct 3 ms 6560 KB Output is correct
50 Correct 2 ms 6636 KB Output is correct
51 Correct 2 ms 6492 KB Output is correct
52 Correct 2 ms 6492 KB Output is correct
53 Correct 2 ms 6492 KB Output is correct
54 Correct 3 ms 6492 KB Output is correct
55 Correct 2 ms 6492 KB Output is correct
56 Correct 2 ms 6492 KB Output is correct
57 Correct 3 ms 6748 KB Output is correct
58 Correct 2 ms 6648 KB Output is correct
59 Correct 2 ms 6492 KB Output is correct
60 Correct 2 ms 6492 KB Output is correct
61 Correct 2 ms 6492 KB Output is correct
62 Correct 2 ms 6492 KB Output is correct
63 Correct 2 ms 6492 KB Output is correct
64 Correct 80 ms 14632 KB Output is correct
65 Correct 84 ms 14672 KB Output is correct
66 Correct 72 ms 14676 KB Output is correct
67 Correct 71 ms 14768 KB Output is correct
68 Correct 73 ms 14564 KB Output is correct
69 Correct 107 ms 14700 KB Output is correct
70 Correct 73 ms 14672 KB Output is correct
71 Correct 69 ms 14672 KB Output is correct
72 Correct 80 ms 14556 KB Output is correct
73 Correct 144 ms 27476 KB Output is correct
74 Correct 109 ms 27216 KB Output is correct
75 Correct 81 ms 14420 KB Output is correct
76 Correct 69 ms 14416 KB Output is correct
77 Correct 79 ms 14444 KB Output is correct
78 Correct 73 ms 14552 KB Output is correct
79 Correct 77 ms 14644 KB Output is correct
80 Correct 81 ms 14420 KB Output is correct
81 Correct 68 ms 15232 KB Output is correct
82 Correct 66 ms 14796 KB Output is correct
83 Correct 90 ms 19792 KB Output is correct
84 Correct 99 ms 21972 KB Output is correct
85 Correct 89 ms 21572 KB Output is correct
86 Correct 104 ms 15968 KB Output is correct
87 Correct 81 ms 15444 KB Output is correct
88 Correct 76 ms 15772 KB Output is correct
89 Correct 79 ms 15868 KB Output is correct
90 Correct 76 ms 15608 KB Output is correct
91 Correct 88 ms 15924 KB Output is correct
92 Correct 80 ms 16328 KB Output is correct
93 Correct 78 ms 18676 KB Output is correct
94 Correct 73 ms 20268 KB Output is correct
95 Correct 88 ms 19064 KB Output is correct
96 Correct 74 ms 17232 KB Output is correct
97 Correct 74 ms 15724 KB Output is correct
98 Correct 71 ms 15264 KB Output is correct
99 Correct 102 ms 14920 KB Output is correct
100 Correct 102 ms 18188 KB Output is correct
101 Correct 75 ms 16032 KB Output is correct
102 Correct 71 ms 15360 KB Output is correct
103 Correct 71 ms 15236 KB Output is correct
104 Correct 47 ms 15324 KB Output is correct
105 Correct 94 ms 24144 KB Output is correct
106 Correct 67 ms 15144 KB Output is correct
107 Correct 61 ms 15264 KB Output is correct
108 Correct 112 ms 28388 KB Output is correct
109 Correct 66 ms 15516 KB Output is correct
110 Correct 95 ms 28308 KB Output is correct
111 Correct 64 ms 14416 KB Output is correct