답안 #967704

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
967704 2024-04-22T16:23:24 Z Lecorbio Power Plant (JOI20_power) C++17
100 / 100
109 ms 29036 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define sajz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

const int N = 2e5+7;
string type; int n, dp[N], res = 0;
vector<int> g[N];

void dfs(int v, int par){
	int mx = 0;
	for (auto u : g[v]){
		if (u == par) continue;
		dfs(u, v);
		dp[v] += dp[u];
		mx = max(mx, dp[u]);
	}
	
	if (type[v-1] == '1'){
		dp[v] = max(1, dp[v] - 1);
		res = max(res, mx + 1);
	}
	res = max(res, dp[v]);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> n;
    for (int i=0; i<n-1; i++){
		int a, b; cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	cin >> type;
	
	dfs(1, 1);
	//for (int i=1; i<=n; i++) cout << i << ": " << dp[i] << '\n';
	cout << res << '\n';
 
    return 0;
}
/*

6
2 3
4 3
1 3
3 5
6 2
110011

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 5160 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 1 ms 4952 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 5152 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 1 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
20 Correct 1 ms 4956 KB Output is correct
21 Correct 1 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 5160 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 1 ms 4952 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 5152 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 1 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
20 Correct 1 ms 4956 KB Output is correct
21 Correct 1 ms 4956 KB Output is correct
22 Correct 2 ms 5212 KB Output is correct
23 Correct 2 ms 5212 KB Output is correct
24 Correct 2 ms 5212 KB Output is correct
25 Correct 2 ms 5212 KB Output is correct
26 Correct 2 ms 5212 KB Output is correct
27 Correct 2 ms 5168 KB Output is correct
28 Correct 2 ms 5212 KB Output is correct
29 Correct 2 ms 5212 KB Output is correct
30 Correct 3 ms 5172 KB Output is correct
31 Correct 2 ms 5212 KB Output is correct
32 Correct 2 ms 5428 KB Output is correct
33 Correct 2 ms 5208 KB Output is correct
34 Correct 2 ms 5212 KB Output is correct
35 Correct 2 ms 5212 KB Output is correct
36 Correct 2 ms 5212 KB Output is correct
37 Correct 2 ms 5212 KB Output is correct
38 Correct 2 ms 5212 KB Output is correct
39 Correct 2 ms 5180 KB Output is correct
40 Correct 2 ms 5212 KB Output is correct
41 Correct 2 ms 5212 KB Output is correct
42 Correct 2 ms 5212 KB Output is correct
43 Correct 2 ms 5208 KB Output is correct
44 Correct 2 ms 5208 KB Output is correct
45 Correct 2 ms 5208 KB Output is correct
46 Correct 2 ms 5208 KB Output is correct
47 Correct 2 ms 5208 KB Output is correct
48 Correct 2 ms 5212 KB Output is correct
49 Correct 2 ms 5208 KB Output is correct
50 Correct 2 ms 5212 KB Output is correct
51 Correct 2 ms 5212 KB Output is correct
52 Correct 2 ms 5236 KB Output is correct
53 Correct 2 ms 5212 KB Output is correct
54 Correct 2 ms 5212 KB Output is correct
55 Correct 2 ms 5168 KB Output is correct
56 Correct 2 ms 5208 KB Output is correct
57 Correct 2 ms 5212 KB Output is correct
58 Correct 2 ms 5208 KB Output is correct
59 Correct 2 ms 5212 KB Output is correct
60 Correct 2 ms 5208 KB Output is correct
61 Correct 2 ms 5212 KB Output is correct
62 Correct 2 ms 5212 KB Output is correct
63 Correct 2 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 5160 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 1 ms 4952 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 5152 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 1 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
20 Correct 1 ms 4956 KB Output is correct
21 Correct 1 ms 4956 KB Output is correct
22 Correct 2 ms 5212 KB Output is correct
23 Correct 2 ms 5212 KB Output is correct
24 Correct 2 ms 5212 KB Output is correct
25 Correct 2 ms 5212 KB Output is correct
26 Correct 2 ms 5212 KB Output is correct
27 Correct 2 ms 5168 KB Output is correct
28 Correct 2 ms 5212 KB Output is correct
29 Correct 2 ms 5212 KB Output is correct
30 Correct 3 ms 5172 KB Output is correct
31 Correct 2 ms 5212 KB Output is correct
32 Correct 2 ms 5428 KB Output is correct
33 Correct 2 ms 5208 KB Output is correct
34 Correct 2 ms 5212 KB Output is correct
35 Correct 2 ms 5212 KB Output is correct
36 Correct 2 ms 5212 KB Output is correct
37 Correct 2 ms 5212 KB Output is correct
38 Correct 2 ms 5212 KB Output is correct
39 Correct 2 ms 5180 KB Output is correct
40 Correct 2 ms 5212 KB Output is correct
41 Correct 2 ms 5212 KB Output is correct
42 Correct 2 ms 5212 KB Output is correct
43 Correct 2 ms 5208 KB Output is correct
44 Correct 2 ms 5208 KB Output is correct
45 Correct 2 ms 5208 KB Output is correct
46 Correct 2 ms 5208 KB Output is correct
47 Correct 2 ms 5208 KB Output is correct
48 Correct 2 ms 5212 KB Output is correct
49 Correct 2 ms 5208 KB Output is correct
50 Correct 2 ms 5212 KB Output is correct
51 Correct 2 ms 5212 KB Output is correct
52 Correct 2 ms 5236 KB Output is correct
53 Correct 2 ms 5212 KB Output is correct
54 Correct 2 ms 5212 KB Output is correct
55 Correct 2 ms 5168 KB Output is correct
56 Correct 2 ms 5208 KB Output is correct
57 Correct 2 ms 5212 KB Output is correct
58 Correct 2 ms 5208 KB Output is correct
59 Correct 2 ms 5212 KB Output is correct
60 Correct 2 ms 5208 KB Output is correct
61 Correct 2 ms 5212 KB Output is correct
62 Correct 2 ms 5212 KB Output is correct
63 Correct 2 ms 5212 KB Output is correct
64 Correct 98 ms 15144 KB Output is correct
65 Correct 67 ms 15252 KB Output is correct
66 Correct 87 ms 15212 KB Output is correct
67 Correct 64 ms 15236 KB Output is correct
68 Correct 66 ms 15232 KB Output is correct
69 Correct 70 ms 15340 KB Output is correct
70 Correct 62 ms 15232 KB Output is correct
71 Correct 77 ms 15260 KB Output is correct
72 Correct 62 ms 15240 KB Output is correct
73 Correct 101 ms 27932 KB Output is correct
74 Correct 76 ms 27796 KB Output is correct
75 Correct 58 ms 14996 KB Output is correct
76 Correct 59 ms 14996 KB Output is correct
77 Correct 95 ms 14988 KB Output is correct
78 Correct 85 ms 14992 KB Output is correct
79 Correct 64 ms 15012 KB Output is correct
80 Correct 57 ms 14992 KB Output is correct
81 Correct 63 ms 15420 KB Output is correct
82 Correct 75 ms 15440 KB Output is correct
83 Correct 72 ms 20428 KB Output is correct
84 Correct 106 ms 22516 KB Output is correct
85 Correct 109 ms 22168 KB Output is correct
86 Correct 65 ms 16528 KB Output is correct
87 Correct 62 ms 16060 KB Output is correct
88 Correct 58 ms 16352 KB Output is correct
89 Correct 70 ms 16704 KB Output is correct
90 Correct 93 ms 16164 KB Output is correct
91 Correct 60 ms 16500 KB Output is correct
92 Correct 58 ms 16764 KB Output is correct
93 Correct 61 ms 19120 KB Output is correct
94 Correct 85 ms 21100 KB Output is correct
95 Correct 84 ms 19528 KB Output is correct
96 Correct 61 ms 17916 KB Output is correct
97 Correct 61 ms 16268 KB Output is correct
98 Correct 59 ms 15812 KB Output is correct
99 Correct 57 ms 15500 KB Output is correct
100 Correct 94 ms 18812 KB Output is correct
101 Correct 76 ms 16652 KB Output is correct
102 Correct 59 ms 15972 KB Output is correct
103 Correct 68 ms 15812 KB Output is correct
104 Correct 59 ms 15304 KB Output is correct
105 Correct 88 ms 24568 KB Output is correct
106 Correct 60 ms 16072 KB Output is correct
107 Correct 44 ms 16072 KB Output is correct
108 Correct 88 ms 28824 KB Output is correct
109 Correct 57 ms 15296 KB Output is correct
110 Correct 74 ms 29036 KB Output is correct
111 Correct 54 ms 15008 KB Output is correct