#include <bits/stdc++.h>
#define forr(_a,_b,_c) for(_a = (_b); _a <= (_c); ++_a)
#define ford(_a,_b,_c) for(_a = (_b) + 1; _a --> (_c);)
#define forf(_a,_b,_c) for(_a = (_b); _a < (_c); ++_a)
#define st first
#define nd second
#define ll long long
#define ull unsigned long long
#define pii pair <int,int>
#define pll pair <int,ll>
#define piii pair <int,pii>
#define vi vector <int>
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define file "test"
using namespace std;
const int N = 2e5 + 5;
const ll oo = 1e9;
const ll mod = 1e9 + 7;
map <int,ll> m[N];
vector <pll> a[N];
ll res, f[N], rk[N], dep[N];
ll k;
void dfs (int u, int p, ll c, int h) {
m[u][c] = h;
rk[u] = c;
dep[u] = h;
ll need = k + 2 * rk[u];
for (pii v : a[u]) {
if (v.st == p) continue;
dfs (v.st, u, c + v.nd, h + 1);
if (m[v.st].size() > m[u].size())
swap(m[v.st], m[u]);
for (pll w : m[v.st])
if (m[u].find(need - w.st) != m[u].end())
res = min(res, m[u][need - w.st] + w.nd - 2 * dep[u]);
for (pll w : m[v.st]) {
if (m[u].find(w.st) == m[u].end())
m[u].insert(w);
else m[u][w.st] = min(m[u][w.st], w.nd);
}
}
}
int n,i,u,v,w;
int best_path (int nn, int kk, int edge[][2], int ww[]){
res = oo;
n = nn;
k = kk;
if (k == 1)
return 0;
forf (i,0,n - 1){
u = edge[i][0];
v = edge[i][1];
w = ww[i];
a[u].pb({v,w});
a[v].pb({u,w});
}
dfs(0,0,0,0);
return (res <= n - 1 ? res : -1);
}
Compilation message
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
collect2: error: ld returned 1 exit status