#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FOD(i, a, b) for(int i = a; i >= b; i--)
#define fi first
#define se second
#define ll long long
#define db double
#define ii pair<int,int>
#define pb push_back
#define MASK(i) (1LL << i)
#define sq(i) (1LL * (i) * (i))
#define task "task"
const ll INF = 1e18;
const int inf = 1e9;
const int N = 2e5 + 4;
int n, k;
vector<ii> g[N];
ll d[N], r[N];
bool ch[N];
void dfs(int u, int p, ll x) {
r[u] = 0;
d[u] = -1;
ll maxr = 0, maxd = -1;
for(ii H : g[u]) {
int v = H.fi;
int w = H.se;
if(v == p) continue;
dfs(v, u, x);
if(r[v] != -1) {
if(r[v] + w > x) {
maxd = max(maxd, x - w);
ch[v] = 1;
}
else {
maxr = max(maxr, r[v] + w);
}
}
else maxd = max(maxd, d[v] - w);
}
if(maxr <= maxd) {
if(maxd != -1) {
d[u] = maxd;
r[u] = -1;
}
}
else {
r[u] = maxr;
}
}
bool check(ll x) {
FOR(i, 1, n) ch[i] = 0;
dfs(1, -1, x);
if(r[1] != -1) ch[1] = 1;
int cnt = 0;
FOR(i, 1, n) cnt += ch[i];
return cnt <= k;
}
void solve() {
ll l = 0, r = 2e14, res = 0;
while(l <= r) {
ll mid = l + r >> 1;
if(check(mid)) {
res = mid;
r = mid - 1;
}
else l = mid + 1;
}
cout << res << '\n';
check(res);
int cnt = 0;
FOR(i, 1, n) cnt += ch[i];
FOR(i, 1, n) {
if(ch[i]) cout << i << ' ';
else if(cnt < k) {
cout << i << ' ';
cnt++;
}
}
}
signed main() {
if(fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
//freopen(task".out", "w", stdout);
}
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int tc = 1;
// cin >> tc;
while(tc--) {
cin >> n >> k;
FOR(i, 1, n - 1) {
int u, v, w;
cin >> u >> v >> w;
g[u].pb({v, w});
g[v].pb({u, w});
}
solve();
}
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
92 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |