hdu3080 The plan of city rebuild

2014-11-24 12:36:40 · 作者: · 浏览: 0

简单最小生成树。

就是读题很纠结,什么原有的路,新建的路,删除的村庄。

总之,所有给的边都加上,删除点的操作就是把与该点相连的所有边删除(边权变成inf就是了),然后求最小生成树。

用kruskal比较方便判断不连通的情况。


#include
  
   
#include
   
     #include
    
      #include
     
       #define inf 0x3f3f3f3f using namespace std; struct node { int u,v,w; }e[40000]; int vis[210],r[210],n,tmp,edge; int root(int a) { if(a!=r[a]) r[a]=root(r[a]); return r[a]; } bool cmp(node a,node b) { if(a.w!=b.w) return a.w