
Kruskal is an efficient algorithm to calculate a minium spwan tree(MST).Its idea is to sort all edges and then choose edges from the shortest to the longest until all vertex are in one set.It can be facilitated by using Union Find(Use it to handle the conversion of vertexes)
the template of kurskal algorithm:
#include
#include
#include
#include
#include
using namespace std;
const int maxm=100;
struct edge{
int n;
int f,t,w;
}e[maxn];
int ans[maxn];
int ecnt=0;
bool mark[maxn];
int f[maxn];
void init(){
for(int i=0;i




近期评论