bzoj 1083 最小生成树
2014-01-11 19:32
369 查看
裸的最小生成树。
/************************************************************** Problem: 1083 User: BLADEVIL Language: Pascal Result: Accepted Time:44 ms Memory:344 kb ****************************************************************/ //By BLADEVIL var n, m :longint; pre, succ, len :array[0..10010] of longint; father :array[0..400] of longint; ans :longint; procedure swap(var a,b:longint); var c :longint; begin c:=a; a:=b; b:=c; end; procedure qs(low,high:longint); var i, j :longint; xx :longint; begin i:=low; j:=high; xx:=len[(i+j)>>1]; while i<j do begin while xx>len[i] do inc(i); while xx<len[j] do dec(j); if i<=j then begin swap(succ[i],succ[j]); swap(pre[i],pre[j]); swap(len[i],len[j]); inc(i); dec(j); end; end; if i<high then qs(i,high); if j>low then qs(low,j); end; procedure init; var i :longint; begin read(n,m); for i:=1 to m do read(pre[i],succ[i],len[i]); qs(1,m); end; function getfather(x:longint):longint; begin if father[x]=x then exit(x); father[x]:=getfather(father[x]); exit(father[x]); end; procedure main; var i :longint; a, b, fa, fb :longint; begin for i:=1 to n do father[i]:=i; for i:=1 to m do begin a:=pre[i]; b:=succ[i]; fa:=getfather(a); fb:=getfather(b); if fa<>fb then begin ans:=len[i]; father[fa]:=fb; end; end; writeln(n-1,' ',ans); end; begin init; main; end.
相关文章推荐
- 反模式 了解吗?
- 代码复用应该这样做(2)
- ngx_lua 一些性能分析方法
- ubuintu 12.04 server 系统语言
- 如何进行软件系统架构设计?
- vim之vba文件
- Java命令参数说明大全
- 架构师小掌握哪些知识
- Timus 1238. Folding
- linux shell之易经起卦
- ubuntu apt-get 获得内核源代码
- 驱动之cdev
- Windows2008R2 安装Oracle11.2.0.3 85%EM报错
- undo管理
- 信号之sigprocmask函数
- 11g用户密码过期处理办法
- 猜数字小游戏
- Top Android App使用的组件
- centos-6更新yum源(163)
- centos-6更新yum源(163)