답안 #1113931

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1113931 2024-11-17T20:48:48 Z Dan4Life Power Plant (JOI20_power) C++17
100 / 100
127 ms 34500 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
const int N = (int)2e5+2;
int n;
string gen;
vector<int> adj[N];
int dp[N], ans;

int dfs(int s, int p){
	vector<int> v; v.clear();
	for(auto u : adj[s]){
		if(u==p) continue;
		dfs(u,s); v.pb(dp[u]);
	}
	int sum = 0, best = 0, ok = (gen[s]=='1');
	for(auto u : v) sum+=u, best=max(best,u);
	ans = max({ans, sum-ok, best+ok});
	dp[s] = max(ok,sum-ok); return ans;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for(int i = 1; i < n; i++){
		int a, b; cin >> a >> b;
		adj[a].pb(b), adj[b].pb(a);
	}
	cin >> gen; gen='$'+gen;
	cout << dfs(1,-1) << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5712 KB Output is correct
2 Correct 3 ms 5712 KB Output is correct
3 Correct 2 ms 5712 KB Output is correct
4 Correct 2 ms 5712 KB Output is correct
5 Correct 2 ms 5768 KB Output is correct
6 Correct 3 ms 5880 KB Output is correct
7 Correct 2 ms 5712 KB Output is correct
8 Correct 2 ms 5712 KB Output is correct
9 Correct 3 ms 5712 KB Output is correct
10 Correct 2 ms 5712 KB Output is correct
11 Correct 2 ms 5712 KB Output is correct
12 Correct 2 ms 5712 KB Output is correct
13 Correct 3 ms 5712 KB Output is correct
14 Correct 3 ms 5712 KB Output is correct
15 Correct 2 ms 5712 KB Output is correct
16 Correct 2 ms 5712 KB Output is correct
17 Correct 2 ms 5712 KB Output is correct
18 Correct 2 ms 5712 KB Output is correct
19 Correct 3 ms 5712 KB Output is correct
20 Correct 4 ms 5968 KB Output is correct
21 Correct 2 ms 5712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5712 KB Output is correct
2 Correct 3 ms 5712 KB Output is correct
3 Correct 2 ms 5712 KB Output is correct
4 Correct 2 ms 5712 KB Output is correct
5 Correct 2 ms 5768 KB Output is correct
6 Correct 3 ms 5880 KB Output is correct
7 Correct 2 ms 5712 KB Output is correct
8 Correct 2 ms 5712 KB Output is correct
9 Correct 3 ms 5712 KB Output is correct
10 Correct 2 ms 5712 KB Output is correct
11 Correct 2 ms 5712 KB Output is correct
12 Correct 2 ms 5712 KB Output is correct
13 Correct 3 ms 5712 KB Output is correct
14 Correct 3 ms 5712 KB Output is correct
15 Correct 2 ms 5712 KB Output is correct
16 Correct 2 ms 5712 KB Output is correct
17 Correct 2 ms 5712 KB Output is correct
18 Correct 2 ms 5712 KB Output is correct
19 Correct 3 ms 5712 KB Output is correct
20 Correct 4 ms 5968 KB Output is correct
21 Correct 2 ms 5712 KB Output is correct
22 Correct 3 ms 5712 KB Output is correct
23 Correct 3 ms 5712 KB Output is correct
24 Correct 3 ms 5880 KB Output is correct
25 Correct 3 ms 5712 KB Output is correct
26 Correct 2 ms 5712 KB Output is correct
27 Correct 3 ms 5712 KB Output is correct
28 Correct 3 ms 5712 KB Output is correct
29 Correct 3 ms 5968 KB Output is correct
30 Correct 3 ms 5968 KB Output is correct
31 Correct 3 ms 5712 KB Output is correct
32 Correct 3 ms 5824 KB Output is correct
33 Correct 3 ms 5712 KB Output is correct
34 Correct 2 ms 5712 KB Output is correct
35 Correct 3 ms 5712 KB Output is correct
36 Correct 3 ms 5712 KB Output is correct
37 Correct 3 ms 5712 KB Output is correct
38 Correct 3 ms 5712 KB Output is correct
39 Correct 3 ms 5968 KB Output is correct
40 Correct 3 ms 5724 KB Output is correct
41 Correct 3 ms 5712 KB Output is correct
42 Correct 3 ms 5712 KB Output is correct
43 Correct 4 ms 5712 KB Output is correct
44 Correct 3 ms 5944 KB Output is correct
45 Correct 3 ms 5712 KB Output is correct
46 Correct 3 ms 5712 KB Output is correct
47 Correct 3 ms 5712 KB Output is correct
48 Correct 3 ms 5968 KB Output is correct
49 Correct 3 ms 5968 KB Output is correct
50 Correct 4 ms 5712 KB Output is correct
51 Correct 3 ms 5712 KB Output is correct
52 Correct 3 ms 5712 KB Output is correct
53 Correct 3 ms 5712 KB Output is correct
54 Correct 3 ms 5712 KB Output is correct
55 Correct 3 ms 5712 KB Output is correct
56 Correct 3 ms 5712 KB Output is correct
57 Correct 4 ms 5968 KB Output is correct
58 Correct 3 ms 5880 KB Output is correct
59 Correct 3 ms 5896 KB Output is correct
60 Correct 3 ms 5848 KB Output is correct
61 Correct 3 ms 5712 KB Output is correct
62 Correct 4 ms 5780 KB Output is correct
63 Correct 3 ms 5712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5712 KB Output is correct
2 Correct 3 ms 5712 KB Output is correct
3 Correct 2 ms 5712 KB Output is correct
4 Correct 2 ms 5712 KB Output is correct
5 Correct 2 ms 5768 KB Output is correct
6 Correct 3 ms 5880 KB Output is correct
7 Correct 2 ms 5712 KB Output is correct
8 Correct 2 ms 5712 KB Output is correct
9 Correct 3 ms 5712 KB Output is correct
10 Correct 2 ms 5712 KB Output is correct
11 Correct 2 ms 5712 KB Output is correct
12 Correct 2 ms 5712 KB Output is correct
13 Correct 3 ms 5712 KB Output is correct
14 Correct 3 ms 5712 KB Output is correct
15 Correct 2 ms 5712 KB Output is correct
16 Correct 2 ms 5712 KB Output is correct
17 Correct 2 ms 5712 KB Output is correct
18 Correct 2 ms 5712 KB Output is correct
19 Correct 3 ms 5712 KB Output is correct
20 Correct 4 ms 5968 KB Output is correct
21 Correct 2 ms 5712 KB Output is correct
22 Correct 3 ms 5712 KB Output is correct
23 Correct 3 ms 5712 KB Output is correct
24 Correct 3 ms 5880 KB Output is correct
25 Correct 3 ms 5712 KB Output is correct
26 Correct 2 ms 5712 KB Output is correct
27 Correct 3 ms 5712 KB Output is correct
28 Correct 3 ms 5712 KB Output is correct
29 Correct 3 ms 5968 KB Output is correct
30 Correct 3 ms 5968 KB Output is correct
31 Correct 3 ms 5712 KB Output is correct
32 Correct 3 ms 5824 KB Output is correct
33 Correct 3 ms 5712 KB Output is correct
34 Correct 2 ms 5712 KB Output is correct
35 Correct 3 ms 5712 KB Output is correct
36 Correct 3 ms 5712 KB Output is correct
37 Correct 3 ms 5712 KB Output is correct
38 Correct 3 ms 5712 KB Output is correct
39 Correct 3 ms 5968 KB Output is correct
40 Correct 3 ms 5724 KB Output is correct
41 Correct 3 ms 5712 KB Output is correct
42 Correct 3 ms 5712 KB Output is correct
43 Correct 4 ms 5712 KB Output is correct
44 Correct 3 ms 5944 KB Output is correct
45 Correct 3 ms 5712 KB Output is correct
46 Correct 3 ms 5712 KB Output is correct
47 Correct 3 ms 5712 KB Output is correct
48 Correct 3 ms 5968 KB Output is correct
49 Correct 3 ms 5968 KB Output is correct
50 Correct 4 ms 5712 KB Output is correct
51 Correct 3 ms 5712 KB Output is correct
52 Correct 3 ms 5712 KB Output is correct
53 Correct 3 ms 5712 KB Output is correct
54 Correct 3 ms 5712 KB Output is correct
55 Correct 3 ms 5712 KB Output is correct
56 Correct 3 ms 5712 KB Output is correct
57 Correct 4 ms 5968 KB Output is correct
58 Correct 3 ms 5880 KB Output is correct
59 Correct 3 ms 5896 KB Output is correct
60 Correct 3 ms 5848 KB Output is correct
61 Correct 3 ms 5712 KB Output is correct
62 Correct 4 ms 5780 KB Output is correct
63 Correct 3 ms 5712 KB Output is correct
64 Correct 72 ms 15312 KB Output is correct
65 Correct 65 ms 15308 KB Output is correct
66 Correct 71 ms 15284 KB Output is correct
67 Correct 66 ms 15308 KB Output is correct
68 Correct 60 ms 15284 KB Output is correct
69 Correct 65 ms 15300 KB Output is correct
70 Correct 60 ms 15268 KB Output is correct
71 Correct 61 ms 15312 KB Output is correct
72 Correct 65 ms 15224 KB Output is correct
73 Correct 107 ms 33040 KB Output is correct
74 Correct 89 ms 32964 KB Output is correct
75 Correct 68 ms 15120 KB Output is correct
76 Correct 57 ms 15208 KB Output is correct
77 Correct 61 ms 15236 KB Output is correct
78 Correct 60 ms 15240 KB Output is correct
79 Correct 59 ms 15248 KB Output is correct
80 Correct 57 ms 15236 KB Output is correct
81 Correct 58 ms 16060 KB Output is correct
82 Correct 60 ms 15604 KB Output is correct
83 Correct 78 ms 22728 KB Output is correct
84 Correct 75 ms 26068 KB Output is correct
85 Correct 85 ms 25380 KB Output is correct
86 Correct 88 ms 17296 KB Output is correct
87 Correct 64 ms 16320 KB Output is correct
88 Correct 61 ms 16648 KB Output is correct
89 Correct 58 ms 16848 KB Output is correct
90 Correct 61 ms 16396 KB Output is correct
91 Correct 61 ms 16804 KB Output is correct
92 Correct 77 ms 17120 KB Output is correct
93 Correct 83 ms 20992 KB Output is correct
94 Correct 87 ms 23112 KB Output is correct
95 Correct 66 ms 21628 KB Output is correct
96 Correct 84 ms 18616 KB Output is correct
97 Correct 63 ms 16464 KB Output is correct
98 Correct 86 ms 15860 KB Output is correct
99 Correct 67 ms 15552 KB Output is correct
100 Correct 86 ms 20040 KB Output is correct
101 Correct 95 ms 17180 KB Output is correct
102 Correct 82 ms 16020 KB Output is correct
103 Correct 71 ms 15776 KB Output is correct
104 Correct 59 ms 17504 KB Output is correct
105 Correct 89 ms 28356 KB Output is correct
106 Correct 49 ms 17340 KB Output is correct
107 Correct 50 ms 17296 KB Output is correct
108 Correct 94 ms 33992 KB Output is correct
109 Correct 59 ms 17324 KB Output is correct
110 Correct 127 ms 34500 KB Output is correct
111 Correct 57 ms 15232 KB Output is correct