답안 #908530

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
908530 2024-01-16T13:37:00 Z arashMLG Power Plant (JOI20_power) C++17
100 / 100
156 ms 42016 KB
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>   pll;
 
const int N = 5e5 + 23;
const ll inf = 1e18;
 
#define F                  first
#define S                  second
#define pb	               push_back
#define sz(x)              ((int)x.size())
#define kill(x)            cout<<x , exit(0);
#define all(x)             x.begin(),x.end()
#define lc                 (v<<1)
#define rc                 ((v<<1)|1)
#define debug(x)           cerr<< #x << " : " << x << '\n';
#define int               	ll
 
int n;
int dp[N][2];
vector<int> G[N];
bool is[N];
 
void dfs(int v,int p=-1) {
	int sum0 = 0,sum1 = 0,mx1=0,mx0=0;
	for(int u : G[v]) if(u != p) {
		dfs(u,v);
		sum0 += dp[u][0];
		sum1 += dp[u][1];
		mx1= max(mx1,dp[u][1]);
		mx0=max(mx0,dp[u][0]);
	}
	
	if(is[v]) {
		dp[v][0] = max({mx0,sum1- 1,1 + mx1});
	} else {
		dp[v][0] = max({mx0,sum1});
	}
	if(is[v]) {
		dp[v][1] = max({1LL,sum1-1});
	} else {
		dp[v][1] = sum1;
	}
	
}
 
int32_t main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	cin>>n;
	for(int i = 1; i< n ; i++) {
		int v,u; cin>>v>>u;
		G[v].pb(u);
		G[u].pb(v);
	}
	for(int i = 1; i <= n ; i++) {
		char c; cin>>c;
		is[i] = (c == '1');
	}
	int ans =0;
	dfs(1);
	cout<<dp[1][0] << '\n';
	return 0;
}

Compilation message

power.cpp: In function 'int32_t main()':
power.cpp:62:6: warning: unused variable 'ans' [-Wunused-variable]
   62 |  int ans =0;
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 12636 KB Output is correct
2 Correct 6 ms 12636 KB Output is correct
3 Correct 4 ms 12636 KB Output is correct
4 Correct 3 ms 12636 KB Output is correct
5 Correct 4 ms 12636 KB Output is correct
6 Correct 3 ms 12636 KB Output is correct
7 Correct 3 ms 12632 KB Output is correct
8 Correct 3 ms 12636 KB Output is correct
9 Correct 3 ms 12636 KB Output is correct
10 Correct 4 ms 12636 KB Output is correct
11 Correct 4 ms 12776 KB Output is correct
12 Correct 4 ms 12636 KB Output is correct
13 Correct 4 ms 12632 KB Output is correct
14 Correct 4 ms 12632 KB Output is correct
15 Correct 4 ms 12636 KB Output is correct
16 Correct 4 ms 12636 KB Output is correct
17 Correct 4 ms 12636 KB Output is correct
18 Correct 3 ms 12636 KB Output is correct
19 Correct 6 ms 12636 KB Output is correct
20 Correct 4 ms 12632 KB Output is correct
21 Correct 3 ms 12732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 12636 KB Output is correct
2 Correct 6 ms 12636 KB Output is correct
3 Correct 4 ms 12636 KB Output is correct
4 Correct 3 ms 12636 KB Output is correct
5 Correct 4 ms 12636 KB Output is correct
6 Correct 3 ms 12636 KB Output is correct
7 Correct 3 ms 12632 KB Output is correct
8 Correct 3 ms 12636 KB Output is correct
9 Correct 3 ms 12636 KB Output is correct
10 Correct 4 ms 12636 KB Output is correct
11 Correct 4 ms 12776 KB Output is correct
12 Correct 4 ms 12636 KB Output is correct
13 Correct 4 ms 12632 KB Output is correct
14 Correct 4 ms 12632 KB Output is correct
15 Correct 4 ms 12636 KB Output is correct
16 Correct 4 ms 12636 KB Output is correct
17 Correct 4 ms 12636 KB Output is correct
18 Correct 3 ms 12636 KB Output is correct
19 Correct 6 ms 12636 KB Output is correct
20 Correct 4 ms 12632 KB Output is correct
21 Correct 3 ms 12732 KB Output is correct
22 Correct 5 ms 12632 KB Output is correct
23 Correct 4 ms 12888 KB Output is correct
24 Correct 4 ms 12636 KB Output is correct
25 Correct 4 ms 12636 KB Output is correct
26 Correct 4 ms 12632 KB Output is correct
27 Correct 4 ms 12636 KB Output is correct
28 Correct 5 ms 12636 KB Output is correct
29 Correct 4 ms 12892 KB Output is correct
30 Correct 4 ms 12892 KB Output is correct
31 Correct 4 ms 12888 KB Output is correct
32 Correct 4 ms 12636 KB Output is correct
33 Correct 6 ms 12636 KB Output is correct
34 Correct 4 ms 12636 KB Output is correct
35 Correct 4 ms 12636 KB Output is correct
36 Correct 4 ms 12636 KB Output is correct
37 Correct 4 ms 12876 KB Output is correct
38 Correct 4 ms 12732 KB Output is correct
39 Correct 5 ms 12888 KB Output is correct
40 Correct 4 ms 12892 KB Output is correct
41 Correct 4 ms 12740 KB Output is correct
42 Correct 5 ms 12892 KB Output is correct
43 Correct 4 ms 12892 KB Output is correct
44 Correct 4 ms 12892 KB Output is correct
45 Correct 4 ms 12892 KB Output is correct
46 Correct 4 ms 12788 KB Output is correct
47 Correct 4 ms 12888 KB Output is correct
48 Correct 4 ms 12892 KB Output is correct
49 Correct 4 ms 12892 KB Output is correct
50 Correct 6 ms 12748 KB Output is correct
51 Correct 4 ms 12888 KB Output is correct
52 Correct 4 ms 12636 KB Output is correct
53 Correct 5 ms 12892 KB Output is correct
54 Correct 4 ms 12892 KB Output is correct
55 Correct 4 ms 12636 KB Output is correct
56 Correct 4 ms 12636 KB Output is correct
57 Correct 4 ms 12892 KB Output is correct
58 Correct 4 ms 12636 KB Output is correct
59 Correct 4 ms 12636 KB Output is correct
60 Correct 5 ms 12892 KB Output is correct
61 Correct 5 ms 12636 KB Output is correct
62 Correct 5 ms 12856 KB Output is correct
63 Correct 4 ms 12636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 12636 KB Output is correct
2 Correct 6 ms 12636 KB Output is correct
3 Correct 4 ms 12636 KB Output is correct
4 Correct 3 ms 12636 KB Output is correct
5 Correct 4 ms 12636 KB Output is correct
6 Correct 3 ms 12636 KB Output is correct
7 Correct 3 ms 12632 KB Output is correct
8 Correct 3 ms 12636 KB Output is correct
9 Correct 3 ms 12636 KB Output is correct
10 Correct 4 ms 12636 KB Output is correct
11 Correct 4 ms 12776 KB Output is correct
12 Correct 4 ms 12636 KB Output is correct
13 Correct 4 ms 12632 KB Output is correct
14 Correct 4 ms 12632 KB Output is correct
15 Correct 4 ms 12636 KB Output is correct
16 Correct 4 ms 12636 KB Output is correct
17 Correct 4 ms 12636 KB Output is correct
18 Correct 3 ms 12636 KB Output is correct
19 Correct 6 ms 12636 KB Output is correct
20 Correct 4 ms 12632 KB Output is correct
21 Correct 3 ms 12732 KB Output is correct
22 Correct 5 ms 12632 KB Output is correct
23 Correct 4 ms 12888 KB Output is correct
24 Correct 4 ms 12636 KB Output is correct
25 Correct 4 ms 12636 KB Output is correct
26 Correct 4 ms 12632 KB Output is correct
27 Correct 4 ms 12636 KB Output is correct
28 Correct 5 ms 12636 KB Output is correct
29 Correct 4 ms 12892 KB Output is correct
30 Correct 4 ms 12892 KB Output is correct
31 Correct 4 ms 12888 KB Output is correct
32 Correct 4 ms 12636 KB Output is correct
33 Correct 6 ms 12636 KB Output is correct
34 Correct 4 ms 12636 KB Output is correct
35 Correct 4 ms 12636 KB Output is correct
36 Correct 4 ms 12636 KB Output is correct
37 Correct 4 ms 12876 KB Output is correct
38 Correct 4 ms 12732 KB Output is correct
39 Correct 5 ms 12888 KB Output is correct
40 Correct 4 ms 12892 KB Output is correct
41 Correct 4 ms 12740 KB Output is correct
42 Correct 5 ms 12892 KB Output is correct
43 Correct 4 ms 12892 KB Output is correct
44 Correct 4 ms 12892 KB Output is correct
45 Correct 4 ms 12892 KB Output is correct
46 Correct 4 ms 12788 KB Output is correct
47 Correct 4 ms 12888 KB Output is correct
48 Correct 4 ms 12892 KB Output is correct
49 Correct 4 ms 12892 KB Output is correct
50 Correct 6 ms 12748 KB Output is correct
51 Correct 4 ms 12888 KB Output is correct
52 Correct 4 ms 12636 KB Output is correct
53 Correct 5 ms 12892 KB Output is correct
54 Correct 4 ms 12892 KB Output is correct
55 Correct 4 ms 12636 KB Output is correct
56 Correct 4 ms 12636 KB Output is correct
57 Correct 4 ms 12892 KB Output is correct
58 Correct 4 ms 12636 KB Output is correct
59 Correct 4 ms 12636 KB Output is correct
60 Correct 5 ms 12892 KB Output is correct
61 Correct 5 ms 12636 KB Output is correct
62 Correct 5 ms 12856 KB Output is correct
63 Correct 4 ms 12636 KB Output is correct
64 Correct 81 ms 26448 KB Output is correct
65 Correct 103 ms 26708 KB Output is correct
66 Correct 115 ms 26684 KB Output is correct
67 Correct 142 ms 26520 KB Output is correct
68 Correct 85 ms 26716 KB Output is correct
69 Correct 90 ms 26452 KB Output is correct
70 Correct 128 ms 26556 KB Output is correct
71 Correct 79 ms 26704 KB Output is correct
72 Correct 87 ms 26460 KB Output is correct
73 Correct 122 ms 40784 KB Output is correct
74 Correct 109 ms 40784 KB Output is correct
75 Correct 101 ms 27728 KB Output is correct
76 Correct 87 ms 27920 KB Output is correct
77 Correct 103 ms 26656 KB Output is correct
78 Correct 115 ms 26452 KB Output is correct
79 Correct 92 ms 26568 KB Output is correct
80 Correct 115 ms 26452 KB Output is correct
81 Correct 84 ms 26564 KB Output is correct
82 Correct 95 ms 26568 KB Output is correct
83 Correct 156 ms 32592 KB Output is correct
84 Correct 110 ms 35240 KB Output is correct
85 Correct 148 ms 34960 KB Output is correct
86 Correct 111 ms 28244 KB Output is correct
87 Correct 111 ms 27468 KB Output is correct
88 Correct 83 ms 27476 KB Output is correct
89 Correct 81 ms 27732 KB Output is correct
90 Correct 127 ms 27248 KB Output is correct
91 Correct 92 ms 27732 KB Output is correct
92 Correct 113 ms 28072 KB Output is correct
93 Correct 96 ms 30672 KB Output is correct
94 Correct 85 ms 32840 KB Output is correct
95 Correct 127 ms 31284 KB Output is correct
96 Correct 90 ms 29004 KB Output is correct
97 Correct 112 ms 27312 KB Output is correct
98 Correct 84 ms 26708 KB Output is correct
99 Correct 87 ms 26756 KB Output is correct
100 Correct 109 ms 30308 KB Output is correct
101 Correct 110 ms 27812 KB Output is correct
102 Correct 80 ms 27052 KB Output is correct
103 Correct 84 ms 26920 KB Output is correct
104 Correct 73 ms 27864 KB Output is correct
105 Correct 154 ms 36992 KB Output is correct
106 Correct 55 ms 27072 KB Output is correct
107 Correct 63 ms 27068 KB Output is correct
108 Correct 146 ms 41560 KB Output is correct
109 Correct 63 ms 27328 KB Output is correct
110 Correct 124 ms 42016 KB Output is correct
111 Correct 79 ms 26448 KB Output is correct