답안 #341470

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
341470 2020-12-29T19:43:24 Z ryansee Power Plant (JOI20_power) C++14
100 / 100
199 ms 28460 KB
#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 

long long LLINF = 1e18;
int INF = 1e9+1e6;
#define MAXN (200006)
ll n, dp[MAXN][2], ans;
vector<int> v[MAXN];
string A;
void dfs(int x,int p) {
	for(auto i:v[x]) if(i^p) dfs(i, x);
	for(auto i:v[x]) if(i^p) dp[x][0] += dp[i][0];
	if(A[x-1] == '1') {
		for(auto i:v[x]) if(i^p) dp[x][1] += max(dp[i][0], dp[i][1]);
		-- dp[x][1];
		for(auto i:v[x]) if(i^p) ans = max(ans, dp[x][0] - dp[i][0] + dp[i][1] + 1);
		dp[x][1] = max(dp[x][1], dp[x][0] + 1);
	} else {
		for(auto i:v[x]) if(i^p) dp[x][1] += max(dp[i][0], dp[i][1]);
	}
}
int main() {
	FAST
	cin>>n;
	FOR(i,2,n){
		ll a,b;
		cin>>a>>b;
		v[a].eb(b), v[b].eb(a);
	}
	cin>>A;
	dfs(1, 1);
	cout<<max({dp[1][0], dp[1][1], dp[1][2], ans})<<'\n';
}

Compilation message

power.cpp: In function 'int main()':
power.cpp:54:40: warning: array subscript 2 is above array bounds of 'll [2]' {aka 'long long int [2]'} [-Warray-bounds]
   54 |  cout<<max({dp[1][0], dp[1][1], dp[1][2], ans})<<'\n';
      |                                 ~~~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5100 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 3 ms 5100 KB Output is correct
5 Correct 4 ms 5100 KB Output is correct
6 Correct 4 ms 5100 KB Output is correct
7 Correct 4 ms 5100 KB Output is correct
8 Correct 4 ms 5100 KB Output is correct
9 Correct 3 ms 5100 KB Output is correct
10 Correct 3 ms 5100 KB Output is correct
11 Correct 3 ms 5100 KB Output is correct
12 Correct 3 ms 5100 KB Output is correct
13 Correct 4 ms 5100 KB Output is correct
14 Correct 4 ms 5100 KB Output is correct
15 Correct 4 ms 5100 KB Output is correct
16 Correct 3 ms 5100 KB Output is correct
17 Correct 3 ms 5100 KB Output is correct
18 Correct 4 ms 5100 KB Output is correct
19 Correct 3 ms 5100 KB Output is correct
20 Correct 4 ms 5100 KB Output is correct
21 Correct 3 ms 5100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5100 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 3 ms 5100 KB Output is correct
5 Correct 4 ms 5100 KB Output is correct
6 Correct 4 ms 5100 KB Output is correct
7 Correct 4 ms 5100 KB Output is correct
8 Correct 4 ms 5100 KB Output is correct
9 Correct 3 ms 5100 KB Output is correct
10 Correct 3 ms 5100 KB Output is correct
11 Correct 3 ms 5100 KB Output is correct
12 Correct 3 ms 5100 KB Output is correct
13 Correct 4 ms 5100 KB Output is correct
14 Correct 4 ms 5100 KB Output is correct
15 Correct 4 ms 5100 KB Output is correct
16 Correct 3 ms 5100 KB Output is correct
17 Correct 3 ms 5100 KB Output is correct
18 Correct 4 ms 5100 KB Output is correct
19 Correct 3 ms 5100 KB Output is correct
20 Correct 4 ms 5100 KB Output is correct
21 Correct 3 ms 5100 KB Output is correct
22 Correct 5 ms 5100 KB Output is correct
23 Correct 4 ms 5100 KB Output is correct
24 Correct 5 ms 5100 KB Output is correct
25 Correct 4 ms 5100 KB Output is correct
26 Correct 5 ms 5100 KB Output is correct
27 Correct 5 ms 5228 KB Output is correct
28 Correct 4 ms 5228 KB Output is correct
29 Correct 4 ms 5228 KB Output is correct
30 Correct 5 ms 5228 KB Output is correct
31 Correct 4 ms 5100 KB Output is correct
32 Correct 4 ms 5100 KB Output is correct
33 Correct 4 ms 5100 KB Output is correct
34 Correct 4 ms 5100 KB Output is correct
35 Correct 4 ms 5100 KB Output is correct
36 Correct 4 ms 5100 KB Output is correct
37 Correct 4 ms 5228 KB Output is correct
38 Correct 4 ms 5228 KB Output is correct
39 Correct 4 ms 5228 KB Output is correct
40 Correct 4 ms 5228 KB Output is correct
41 Correct 4 ms 5228 KB Output is correct
42 Correct 5 ms 5228 KB Output is correct
43 Correct 5 ms 5228 KB Output is correct
44 Correct 4 ms 5228 KB Output is correct
45 Correct 4 ms 5228 KB Output is correct
46 Correct 4 ms 5228 KB Output is correct
47 Correct 4 ms 5228 KB Output is correct
48 Correct 4 ms 5228 KB Output is correct
49 Correct 4 ms 5228 KB Output is correct
50 Correct 4 ms 5228 KB Output is correct
51 Correct 4 ms 5228 KB Output is correct
52 Correct 4 ms 5228 KB Output is correct
53 Correct 4 ms 5228 KB Output is correct
54 Correct 4 ms 5228 KB Output is correct
55 Correct 4 ms 5228 KB Output is correct
56 Correct 4 ms 5100 KB Output is correct
57 Correct 4 ms 5228 KB Output is correct
58 Correct 4 ms 5356 KB Output is correct
59 Correct 4 ms 5228 KB Output is correct
60 Correct 4 ms 5228 KB Output is correct
61 Correct 4 ms 5100 KB Output is correct
62 Correct 4 ms 5228 KB Output is correct
63 Correct 4 ms 5228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5100 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 3 ms 5100 KB Output is correct
5 Correct 4 ms 5100 KB Output is correct
6 Correct 4 ms 5100 KB Output is correct
7 Correct 4 ms 5100 KB Output is correct
8 Correct 4 ms 5100 KB Output is correct
9 Correct 3 ms 5100 KB Output is correct
10 Correct 3 ms 5100 KB Output is correct
11 Correct 3 ms 5100 KB Output is correct
12 Correct 3 ms 5100 KB Output is correct
13 Correct 4 ms 5100 KB Output is correct
14 Correct 4 ms 5100 KB Output is correct
15 Correct 4 ms 5100 KB Output is correct
16 Correct 3 ms 5100 KB Output is correct
17 Correct 3 ms 5100 KB Output is correct
18 Correct 4 ms 5100 KB Output is correct
19 Correct 3 ms 5100 KB Output is correct
20 Correct 4 ms 5100 KB Output is correct
21 Correct 3 ms 5100 KB Output is correct
22 Correct 5 ms 5100 KB Output is correct
23 Correct 4 ms 5100 KB Output is correct
24 Correct 5 ms 5100 KB Output is correct
25 Correct 4 ms 5100 KB Output is correct
26 Correct 5 ms 5100 KB Output is correct
27 Correct 5 ms 5228 KB Output is correct
28 Correct 4 ms 5228 KB Output is correct
29 Correct 4 ms 5228 KB Output is correct
30 Correct 5 ms 5228 KB Output is correct
31 Correct 4 ms 5100 KB Output is correct
32 Correct 4 ms 5100 KB Output is correct
33 Correct 4 ms 5100 KB Output is correct
34 Correct 4 ms 5100 KB Output is correct
35 Correct 4 ms 5100 KB Output is correct
36 Correct 4 ms 5100 KB Output is correct
37 Correct 4 ms 5228 KB Output is correct
38 Correct 4 ms 5228 KB Output is correct
39 Correct 4 ms 5228 KB Output is correct
40 Correct 4 ms 5228 KB Output is correct
41 Correct 4 ms 5228 KB Output is correct
42 Correct 5 ms 5228 KB Output is correct
43 Correct 5 ms 5228 KB Output is correct
44 Correct 4 ms 5228 KB Output is correct
45 Correct 4 ms 5228 KB Output is correct
46 Correct 4 ms 5228 KB Output is correct
47 Correct 4 ms 5228 KB Output is correct
48 Correct 4 ms 5228 KB Output is correct
49 Correct 4 ms 5228 KB Output is correct
50 Correct 4 ms 5228 KB Output is correct
51 Correct 4 ms 5228 KB Output is correct
52 Correct 4 ms 5228 KB Output is correct
53 Correct 4 ms 5228 KB Output is correct
54 Correct 4 ms 5228 KB Output is correct
55 Correct 4 ms 5228 KB Output is correct
56 Correct 4 ms 5100 KB Output is correct
57 Correct 4 ms 5228 KB Output is correct
58 Correct 4 ms 5356 KB Output is correct
59 Correct 4 ms 5228 KB Output is correct
60 Correct 4 ms 5228 KB Output is correct
61 Correct 4 ms 5100 KB Output is correct
62 Correct 4 ms 5228 KB Output is correct
63 Correct 4 ms 5228 KB Output is correct
64 Correct 163 ms 17608 KB Output is correct
65 Correct 164 ms 17580 KB Output is correct
66 Correct 161 ms 17756 KB Output is correct
67 Correct 164 ms 17580 KB Output is correct
68 Correct 158 ms 17580 KB Output is correct
69 Correct 163 ms 17704 KB Output is correct
70 Correct 159 ms 17596 KB Output is correct
71 Correct 159 ms 17592 KB Output is correct
72 Correct 159 ms 17576 KB Output is correct
73 Correct 190 ms 27692 KB Output is correct
74 Correct 189 ms 27564 KB Output is correct
75 Correct 163 ms 17448 KB Output is correct
76 Correct 161 ms 17584 KB Output is correct
77 Correct 172 ms 17448 KB Output is correct
78 Correct 167 ms 17448 KB Output is correct
79 Correct 167 ms 17456 KB Output is correct
80 Correct 169 ms 17448 KB Output is correct
81 Correct 133 ms 17892 KB Output is correct
82 Correct 153 ms 17644 KB Output is correct
83 Correct 199 ms 21680 KB Output is correct
84 Correct 179 ms 23352 KB Output is correct
85 Correct 176 ms 23096 KB Output is correct
86 Correct 196 ms 18604 KB Output is correct
87 Correct 170 ms 18216 KB Output is correct
88 Correct 160 ms 18664 KB Output is correct
89 Correct 161 ms 18744 KB Output is correct
90 Correct 158 ms 18572 KB Output is correct
91 Correct 151 ms 18704 KB Output is correct
92 Correct 159 ms 19096 KB Output is correct
93 Correct 157 ms 20860 KB Output is correct
94 Correct 150 ms 22372 KB Output is correct
95 Correct 146 ms 21220 KB Output is correct
96 Correct 157 ms 19992 KB Output is correct
97 Correct 159 ms 18564 KB Output is correct
98 Correct 146 ms 18224 KB Output is correct
99 Correct 153 ms 17960 KB Output is correct
100 Correct 157 ms 20504 KB Output is correct
101 Correct 158 ms 18856 KB Output is correct
102 Correct 152 ms 18300 KB Output is correct
103 Correct 166 ms 18252 KB Output is correct
104 Correct 90 ms 15328 KB Output is correct
105 Correct 186 ms 25132 KB Output is correct
106 Correct 98 ms 18400 KB Output is correct
107 Correct 100 ms 18400 KB Output is correct
108 Correct 181 ms 28204 KB Output is correct
109 Correct 93 ms 15328 KB Output is correct
110 Correct 193 ms 28460 KB Output is correct
111 Correct 150 ms 17464 KB Output is correct