没啥好说的,排序后贪心,并查集判定连通,达成数量条件就可以输出。
#include<bits/stdc++.h>
#define FOR(a, b, c) for(int a=b; a<=c; a++)
#define maxn 500005
#define maxm 55
#define hrdg 10007
#define zh 16711680
#define inf 2147483647
#define llinf 9223372036854775807
#define ll long long
#define pi acos(-1.0)
#define ls p<<1
#define rs p<<1|1
using namespace std;
int n, m, k, u, v, d, ans;
struct Edge{ int u, v, dis;} edge[maxn];
inline int read(){
char c=getchar();long long x=0,f=1;
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
return x*f;
}
int fa[maxn]; //想了一下还是压了并查集的行,我怎么看我这轮专题的代码那么冗长呢
inline int setfind(int x){ return x == fa[x] ? x : fa[x] = setfind(fa[x]);}
inline void setunion(int x,int y){ x = setfind(fa[x]); y = s