题目链接 Solution 二分答案+并查集. 由于考虑到是要求花费的最小值,直接考虑到二分. 然后对于每一个二分出来的答案,模拟 \(Kruskal\) 的过程再做一遍连边. 同时用并查集维护联通块信息. 最后看连的边数以及\(1\)边是否满足要求即可. Code #include<bits/stdc++.h> using namespace std; const int maxn=20008; int n,k,m,v[maxn]; struct sj {int x,y,w1,w2,id;}…