最小生成树——Kruskal法 题目: 解法: 题目: 解法: 此题是典型的最小生成树问题,题意为建设可以通向每个村庄的道路的最小花费,所以我们需要先对 数据按花费排序,然后再最小生成树就行了,生成树的同时加上花费就可以了。 #include<cstdio> #include<cmath> #include<iostream> #include<algorithm> #include<queue> #define ll long long using namespace std; struct node { int from; int to; int cost; }a[10010];//道路花费 int tree[