HYSBZ 1601(单点带值的最小生成树)
来源:互联网 发布:ov7670 linux源码 编辑:程序博客网 时间:2024/05/18 03:56
题目大意:最小生成树
建源点0与各点连线的权为建水库的大小。
Program aa;var n,i,j,p:longint; u,v,w:array[0..100000] of longint; size,cost:longint; father:array[0..300] of longint;procedure qsort(l,r:longint);var i,j,m,p:longint;begin i:=l;j:=r;m:=w[(l+r) shr 1]; repeat while w[i]<m do inc(i); while w[j]>m do dec(j); if i<=j then begin p:=w[i];w[i]:=w[j];w[j]:=p; p:=u[i];u[i]:=u[j];u[j]:=p; p:=v[i];v[i]:=v[j];v[j]:=p; inc(i);dec(j); end; until i>j; if l<j then qsort(l,j); if i<r then qsort(i,r);end;function getfather(x:longint):longint;begin if father[x]=x then exit(x); father[x]:=getfather(father[x]); exit(father[x]);end;begin read(n); for i:=1 to n do begin read(w[i]); u[i]:=0;v[i]:=i; end; size:=n; for i:=1 to n do for j:=1 to n do begin read(p); if i=j then continue; inc(size); u[size]:=i;v[size]:=j;w[size]:=p; end; qsort(1,size); cost:=0; for i:=0 to n do father[i]:=i; for i:=1 to size do begin if (getfather(u[i])<>getfather(v[i])) then begin inc(cost,w[i]); father[getfather(u[i])]:=father[getfather(v[i])]; end; end; writeln(cost);end.
- HYSBZ 1601(单点带值的最小生成树)
- 带你辨析最小生成树的两种算法
- 单点度限制最小生成树存代码
- HYSBZ 1036 树链剖分(单点更新区间求和求最大值)
- HYSBZ - 1036 树的统计
- 树的统计Count HYSBZ
- 连接的管道(最小生成树)
- Kruskal 最小生成树(输出最小生成树的路径,权值的和) 参考poj 1258
- Prim最小生成树(求,生成树中权值的和,最大权值,最小权值) 参考poj1258 2485
- [kuangbin带你飞]专题六 最小生成树 (prim)(kruskal)(模板)
- HDU 1233 还是畅通工程 (kuangbin带你飞 专题六 最小生成树)
- hdu 1875 畅通工程再续(kuangbin带你飞 专题六:最小生成树)
- POJ 1287 Networking (kuangbin带你飞 专题六:最小生成树)
- POJ 2421 HDOJ 1102 Constructing Roads(kuangbin带你飞 专题六:最小生成树)
- POJ 1679 The Unique MST(kuangbin带你飞 专题六:最小生成树)
- POJ 2349&&ZOJ 1914 Arctic Network(kuangbin带你飞 专题六:最小生成树)
- ZOJ 1586&&FZU 1096 QS Network(kuangbin带你飞 专题六 最小生成树)
- POJ 1789 Truck History(kuangbin带你飞 专题六:最小生成树)
- 整数转化成字符串,字符串转化成整数
- Oracle数据库-建库、建表空间,建用户
- oracle数据库导入导出
- UVaOJ 445 - Marvelous Mazes
- 若爱 就如桃花般地去爱
- HYSBZ 1601(单点带值的最小生成树)
- linux 触屏测试
- ASCII,Unicode和UTF-8
- java IO流学习笔记一
- 蝴蝶兰与鳞托菊
- HYSBZ 1616(纯深搜)
- Spring3 MVC使用@ResponseBody产生很大的响应头
- IOS学习之Tab Bar的使用和视图切换
- 计算机操作系统知识--关于同步互斥的思考1