답안 #732741

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
732741 2023-04-29T08:50:08 Z myrcella Power Plant (JOI20_power) C++17
100 / 100
202 ms 32448 KB
//by szh
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}

const int maxn = 2e5+10;

int n;
vector <int> edge[maxn];
bool mark[maxn];
int dp[maxn][2];

void dfs(int u,int fa) {
	int sum = 0,mx1 = -maxn,mx0 = -maxn;
	for (int v:edge[u]) {
		if (v==fa) continue;
		dfs(v,u);
		sum += dp[v][0];
		mx1 = max(mx1,dp[v][1]);
		mx0 = max(mx0,dp[v][0]);
	}
	if (mark[u]) {
		dp[u][0] = max(sum-1,1);
		dp[u][1] = max(mx1,mx0+1);
		dp[u][1] = max(dp[u][1],sum-1);
	}
	else {
		dp[u][0] = sum;
		dp[u][1] = mx1;
	}
}

int main() {
//	freopen("input.txt","r",stdin);	
	std::ios::sync_with_stdio(false);cin.tie(0);
	cin>>n;
	rep(i,1,n) {
		int u,v;cin>>u>>v;
		edge[u].pb(v);
		edge[v].pb(u);
	}
	string s;cin>>s;
	rep(i,0,n) if (s[i]=='1') mark[i+1]=1;
	dfs(1,-1);
	cout<<max(dp[1][0],dp[1][1]);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 5028 KB Output is correct
4 Correct 3 ms 5024 KB Output is correct
5 Correct 3 ms 5036 KB Output is correct
6 Correct 4 ms 5036 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 5032 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 6 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 5 ms 4948 KB Output is correct
18 Correct 4 ms 5032 KB Output is correct
19 Correct 8 ms 5024 KB Output is correct
20 Correct 3 ms 5032 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 5028 KB Output is correct
4 Correct 3 ms 5024 KB Output is correct
5 Correct 3 ms 5036 KB Output is correct
6 Correct 4 ms 5036 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 5032 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 6 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 5 ms 4948 KB Output is correct
18 Correct 4 ms 5032 KB Output is correct
19 Correct 8 ms 5024 KB Output is correct
20 Correct 3 ms 5032 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 4 ms 5048 KB Output is correct
23 Correct 4 ms 5076 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 5036 KB Output is correct
26 Correct 6 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 4 ms 5044 KB Output is correct
29 Correct 4 ms 5172 KB Output is correct
30 Correct 4 ms 5224 KB Output is correct
31 Correct 4 ms 5076 KB Output is correct
32 Correct 3 ms 5076 KB Output is correct
33 Correct 3 ms 5076 KB Output is correct
34 Correct 4 ms 5092 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 3 ms 5076 KB Output is correct
37 Correct 4 ms 5048 KB Output is correct
38 Correct 3 ms 5020 KB Output is correct
39 Correct 4 ms 5076 KB Output is correct
40 Correct 4 ms 5164 KB Output is correct
41 Correct 3 ms 5204 KB Output is correct
42 Correct 5 ms 5076 KB Output is correct
43 Correct 3 ms 5132 KB Output is correct
44 Correct 4 ms 5092 KB Output is correct
45 Correct 3 ms 5076 KB Output is correct
46 Correct 4 ms 5076 KB Output is correct
47 Correct 4 ms 5052 KB Output is correct
48 Correct 4 ms 5176 KB Output is correct
49 Correct 3 ms 5204 KB Output is correct
50 Correct 3 ms 5076 KB Output is correct
51 Correct 3 ms 5076 KB Output is correct
52 Correct 4 ms 5076 KB Output is correct
53 Correct 3 ms 5172 KB Output is correct
54 Correct 3 ms 5092 KB Output is correct
55 Correct 4 ms 5040 KB Output is correct
56 Correct 4 ms 5076 KB Output is correct
57 Correct 4 ms 5204 KB Output is correct
58 Correct 3 ms 5076 KB Output is correct
59 Correct 4 ms 5048 KB Output is correct
60 Correct 5 ms 5204 KB Output is correct
61 Correct 3 ms 5148 KB Output is correct
62 Correct 4 ms 5204 KB Output is correct
63 Correct 3 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 5028 KB Output is correct
4 Correct 3 ms 5024 KB Output is correct
5 Correct 3 ms 5036 KB Output is correct
6 Correct 4 ms 5036 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 5032 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 6 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 5 ms 4948 KB Output is correct
18 Correct 4 ms 5032 KB Output is correct
19 Correct 8 ms 5024 KB Output is correct
20 Correct 3 ms 5032 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 4 ms 5048 KB Output is correct
23 Correct 4 ms 5076 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 5036 KB Output is correct
26 Correct 6 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 4 ms 5044 KB Output is correct
29 Correct 4 ms 5172 KB Output is correct
30 Correct 4 ms 5224 KB Output is correct
31 Correct 4 ms 5076 KB Output is correct
32 Correct 3 ms 5076 KB Output is correct
33 Correct 3 ms 5076 KB Output is correct
34 Correct 4 ms 5092 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 3 ms 5076 KB Output is correct
37 Correct 4 ms 5048 KB Output is correct
38 Correct 3 ms 5020 KB Output is correct
39 Correct 4 ms 5076 KB Output is correct
40 Correct 4 ms 5164 KB Output is correct
41 Correct 3 ms 5204 KB Output is correct
42 Correct 5 ms 5076 KB Output is correct
43 Correct 3 ms 5132 KB Output is correct
44 Correct 4 ms 5092 KB Output is correct
45 Correct 3 ms 5076 KB Output is correct
46 Correct 4 ms 5076 KB Output is correct
47 Correct 4 ms 5052 KB Output is correct
48 Correct 4 ms 5176 KB Output is correct
49 Correct 3 ms 5204 KB Output is correct
50 Correct 3 ms 5076 KB Output is correct
51 Correct 3 ms 5076 KB Output is correct
52 Correct 4 ms 5076 KB Output is correct
53 Correct 3 ms 5172 KB Output is correct
54 Correct 3 ms 5092 KB Output is correct
55 Correct 4 ms 5040 KB Output is correct
56 Correct 4 ms 5076 KB Output is correct
57 Correct 4 ms 5204 KB Output is correct
58 Correct 3 ms 5076 KB Output is correct
59 Correct 4 ms 5048 KB Output is correct
60 Correct 5 ms 5204 KB Output is correct
61 Correct 3 ms 5148 KB Output is correct
62 Correct 4 ms 5204 KB Output is correct
63 Correct 3 ms 5076 KB Output is correct
64 Correct 134 ms 16156 KB Output is correct
65 Correct 136 ms 16168 KB Output is correct
66 Correct 146 ms 16140 KB Output is correct
67 Correct 145 ms 16080 KB Output is correct
68 Correct 147 ms 16200 KB Output is correct
69 Correct 139 ms 16104 KB Output is correct
70 Correct 138 ms 16188 KB Output is correct
71 Correct 202 ms 16092 KB Output is correct
72 Correct 143 ms 15996 KB Output is correct
73 Correct 166 ms 31244 KB Output is correct
74 Correct 160 ms 31236 KB Output is correct
75 Correct 144 ms 15972 KB Output is correct
76 Correct 153 ms 15976 KB Output is correct
77 Correct 125 ms 16008 KB Output is correct
78 Correct 125 ms 16032 KB Output is correct
79 Correct 119 ms 15980 KB Output is correct
80 Correct 120 ms 15976 KB Output is correct
81 Correct 110 ms 16488 KB Output is correct
82 Correct 110 ms 16204 KB Output is correct
83 Correct 132 ms 22204 KB Output is correct
84 Correct 200 ms 24812 KB Output is correct
85 Correct 142 ms 24504 KB Output is correct
86 Correct 115 ms 17792 KB Output is correct
87 Correct 108 ms 17072 KB Output is correct
88 Correct 110 ms 17504 KB Output is correct
89 Correct 132 ms 17532 KB Output is correct
90 Correct 123 ms 17272 KB Output is correct
91 Correct 125 ms 17588 KB Output is correct
92 Correct 162 ms 17956 KB Output is correct
93 Correct 151 ms 20872 KB Output is correct
94 Correct 111 ms 22900 KB Output is correct
95 Correct 113 ms 21304 KB Output is correct
96 Correct 108 ms 19132 KB Output is correct
97 Correct 110 ms 17252 KB Output is correct
98 Correct 107 ms 16656 KB Output is correct
99 Correct 123 ms 16520 KB Output is correct
100 Correct 121 ms 20344 KB Output is correct
101 Correct 142 ms 17928 KB Output is correct
102 Correct 105 ms 16924 KB Output is correct
103 Correct 120 ms 16720 KB Output is correct
104 Correct 73 ms 16868 KB Output is correct
105 Correct 143 ms 27320 KB Output is correct
106 Correct 68 ms 16872 KB Output is correct
107 Correct 75 ms 16876 KB Output is correct
108 Correct 160 ms 31980 KB Output is correct
109 Correct 73 ms 16832 KB Output is correct
110 Correct 128 ms 32448 KB Output is correct
111 Correct 111 ms 16056 KB Output is correct