답안 #528947

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
528947 2022-02-21T19:56:25 Z penguinhacker Parkovi (COCI22_parkovi) C++14
110 / 110
1330 ms 34256 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

const int mxN=2e5;
int n, k;
vector<ar<int, 2>> adj[mxN];

ll lim, need[mxN], extra[mxN];
bool used[mxN];

void dfs(int u=0, int p=-1) {
	need[u]=0, extra[u]=-1;
	for (ar<int, 2> v : adj[u]) {
		if (v[0]==p)
			continue;
		dfs(v[0], u);
		if (extra[v[0]]!=-1) {
			if (extra[v[0]]>=v[1])
				extra[u]=max(extra[u], extra[v[0]]-v[1]);
		} else {
			if (need[v[0]]+v[1]>lim) {
				used[v[0]]=1;
				extra[v[0]]=lim;
				if (lim>=v[1])
					extra[u]=max(extra[u], lim-v[1]);
			} else
				need[u]=max(need[u], need[v[0]]+v[1]);
		}
	}
	if (extra[u]>=need[u])
		need[u]=0;
	else
		extra[u]=-1;
	if (u==0&&extra[u]==-1)
		used[u]=1;
}

bool ok(ll x) {
	lim=x;
	memset(used, 0, n);
	dfs();
	return count(used, used+n, 1)<=k;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> k;
	ll lb=0, rb=0;
	for (int i=1; i<n; ++i) {
		int u, v, w;
		cin >> u >> v >> w, --u, --v;
		adj[u].push_back({v, w});
		adj[v].push_back({u, w});
		rb+=w;
	}
	while(lb<rb) {
		ll mid=(lb+rb)/2;
		if (ok(mid))
			rb=mid;
		else
			lb=mid+1;
	}
	assert(ok(lb));
	k-=count(used, used+n, 1);
	for (int i=0; i<n&&k; ++i)
		if (!used[i])
			used[i]=1, --k;
	cout << lb << "\n";
	for (int i=0; i<n; ++i)
		if (used[i])
			cout << i+1 << " ";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 2 ms 4940 KB Output is correct
3 Correct 2 ms 5008 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 3 ms 4952 KB Output is correct
6 Correct 2 ms 5020 KB Output is correct
7 Correct 3 ms 5016 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4960 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 5012 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 5068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 170 ms 31288 KB Output is correct
2 Correct 381 ms 31560 KB Output is correct
3 Correct 290 ms 20232 KB Output is correct
4 Correct 1175 ms 18996 KB Output is correct
5 Correct 1172 ms 18576 KB Output is correct
6 Correct 1160 ms 18668 KB Output is correct
7 Correct 543 ms 17388 KB Output is correct
8 Correct 648 ms 16716 KB Output is correct
9 Correct 1136 ms 16024 KB Output is correct
10 Correct 1192 ms 18740 KB Output is correct
11 Correct 832 ms 19524 KB Output is correct
12 Correct 736 ms 19724 KB Output is correct
13 Correct 813 ms 21272 KB Output is correct
14 Correct 353 ms 18712 KB Output is correct
15 Correct 358 ms 18468 KB Output is correct
16 Correct 743 ms 19704 KB Output is correct
17 Correct 744 ms 18992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 343 ms 33368 KB Output is correct
2 Correct 343 ms 33004 KB Output is correct
3 Correct 331 ms 31488 KB Output is correct
4 Correct 297 ms 31432 KB Output is correct
5 Correct 318 ms 33640 KB Output is correct
6 Correct 359 ms 33292 KB Output is correct
7 Correct 385 ms 34256 KB Output is correct
8 Correct 378 ms 33372 KB Output is correct
9 Correct 331 ms 33040 KB Output is correct
10 Correct 311 ms 30524 KB Output is correct
11 Correct 301 ms 28240 KB Output is correct
12 Correct 378 ms 30704 KB Output is correct
13 Correct 406 ms 30800 KB Output is correct
14 Correct 363 ms 30100 KB Output is correct
15 Correct 170 ms 29180 KB Output is correct
16 Correct 172 ms 28056 KB Output is correct
17 Correct 171 ms 28100 KB Output is correct
18 Correct 173 ms 29264 KB Output is correct
19 Correct 187 ms 28996 KB Output is correct
20 Correct 181 ms 29636 KB Output is correct
21 Correct 186 ms 29060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 2 ms 4940 KB Output is correct
3 Correct 2 ms 5008 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 3 ms 4952 KB Output is correct
6 Correct 2 ms 5020 KB Output is correct
7 Correct 3 ms 5016 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4960 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 5012 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 5068 KB Output is correct
15 Correct 170 ms 31288 KB Output is correct
16 Correct 381 ms 31560 KB Output is correct
17 Correct 290 ms 20232 KB Output is correct
18 Correct 1175 ms 18996 KB Output is correct
19 Correct 1172 ms 18576 KB Output is correct
20 Correct 1160 ms 18668 KB Output is correct
21 Correct 543 ms 17388 KB Output is correct
22 Correct 648 ms 16716 KB Output is correct
23 Correct 1136 ms 16024 KB Output is correct
24 Correct 1192 ms 18740 KB Output is correct
25 Correct 832 ms 19524 KB Output is correct
26 Correct 736 ms 19724 KB Output is correct
27 Correct 813 ms 21272 KB Output is correct
28 Correct 353 ms 18712 KB Output is correct
29 Correct 358 ms 18468 KB Output is correct
30 Correct 743 ms 19704 KB Output is correct
31 Correct 744 ms 18992 KB Output is correct
32 Correct 343 ms 33368 KB Output is correct
33 Correct 343 ms 33004 KB Output is correct
34 Correct 331 ms 31488 KB Output is correct
35 Correct 297 ms 31432 KB Output is correct
36 Correct 318 ms 33640 KB Output is correct
37 Correct 359 ms 33292 KB Output is correct
38 Correct 385 ms 34256 KB Output is correct
39 Correct 378 ms 33372 KB Output is correct
40 Correct 331 ms 33040 KB Output is correct
41 Correct 311 ms 30524 KB Output is correct
42 Correct 301 ms 28240 KB Output is correct
43 Correct 378 ms 30704 KB Output is correct
44 Correct 406 ms 30800 KB Output is correct
45 Correct 363 ms 30100 KB Output is correct
46 Correct 170 ms 29180 KB Output is correct
47 Correct 172 ms 28056 KB Output is correct
48 Correct 171 ms 28100 KB Output is correct
49 Correct 173 ms 29264 KB Output is correct
50 Correct 187 ms 28996 KB Output is correct
51 Correct 181 ms 29636 KB Output is correct
52 Correct 186 ms 29060 KB Output is correct
53 Correct 1125 ms 15036 KB Output is correct
54 Correct 1098 ms 15428 KB Output is correct
55 Correct 1238 ms 15808 KB Output is correct
56 Correct 1157 ms 15484 KB Output is correct
57 Correct 1147 ms 15808 KB Output is correct
58 Correct 1116 ms 15128 KB Output is correct
59 Correct 1330 ms 16764 KB Output is correct
60 Correct 596 ms 15748 KB Output is correct
61 Correct 528 ms 14676 KB Output is correct
62 Correct 573 ms 15256 KB Output is correct
63 Correct 599 ms 15784 KB Output is correct
64 Correct 549 ms 16352 KB Output is correct
65 Correct 1187 ms 15460 KB Output is correct
66 Correct 1083 ms 15584 KB Output is correct
67 Correct 1020 ms 14860 KB Output is correct
68 Correct 1169 ms 16732 KB Output is correct
69 Correct 330 ms 29360 KB Output is correct
70 Correct 291 ms 28004 KB Output is correct
71 Correct 372 ms 30468 KB Output is correct
72 Correct 253 ms 15388 KB Output is correct
73 Correct 197 ms 15916 KB Output is correct
74 Correct 163 ms 16544 KB Output is correct
75 Correct 698 ms 16692 KB Output is correct
76 Correct 398 ms 17188 KB Output is correct
77 Correct 764 ms 16608 KB Output is correct
78 Correct 380 ms 16788 KB Output is correct