题目链接 考察并查集,(最小生成树)题目很简单 用k记录树根的个数,k-1就是还需要建设的路 #include#include using namespace std;struct node{ int x,y;}s[1005];int father[1005];int Find(int x){ if(x==father[x]) return x; father[x]=Find(father[x]); return father[x];}void Union(int x,int y){ x=Find(x); y=Find(y); if(x!=y) { father[x]=y; }}int main(void){ int n,m,i,j,k,l; while(scanf("%d",&n)==1&&n) { scanf("%d",&m); for(i=0;i