Solution点分治一下就可以了。#include <bits/stdc++.h> using namespace std; const int N = 40100; int n, k, ans; int head[N], nex[N<<1], to[N<<1], val[N<<1], ce; void add(int u, int v, int w) { to[++ce] = v; nex[ce] = head[u]; head[u] = ce; val[ce] = w; to[++ce] = u; nex- 阅读剩余部分 -