POJ 1258 Agri-Net

2015-07-20 18:04:28 · 作者: · 浏览: 4

题意:就是要你求最小生成树所需的最小距离

思路:Kruskal算法

AC代码:

#include
  
   
#include
   
     #include
    
      using namespace std; #define N 125000 int u[N],v[N],w[N],r[N]; int f[520],str[520][520]; int find(int x) { if(x!=f[x]) f[x]=find(f[x]); return f[x]; } int cmp(const int x,const int y) //间接排序距离 { return w[x]