bzoj 1083 最小生成树
裸的最小生成树。
/**************************************************************
Problem:
User: BLADEVIL
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ //By BLADEVIL
var
n, m :longint;
pre, succ, len :array[..] of longint;
father :array[..] 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)>>];
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:= to m do read(pre[i],succ[i],len[i]);
qs(,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:= to n do father[i]:=i;
for i:= 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-,' ',ans);
end; begin
init;
main;
end.
bzoj 1083 最小生成树的更多相关文章
- Bzoj 1083: [SCOI2005]繁忙的都市 (最小生成树)
Bzoj 1083: [SCOI2005]繁忙的都市 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1083 此题是最小瓶颈生成树的裸题. ...
- BZOJ 1083: [SCOI2005]繁忙的都市【Kruscal最小生成树裸题】
1083: [SCOI2005]繁忙的都市 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2925 Solved: 1927[Submit][Sta ...
- bzoj 1083: [SCOI2005]繁忙的都市 (最小生成树)
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1083 思路:连接所有点,肯定最少是需要n-1条边的,也就是写个最小生成树,记得保存下最大的权 ...
- BZOJ 1083: [SCOI2005]繁忙的都市 裸的最小生成树
题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=1083 代码: #include<iostream> #include< ...
- BZOJ 1083 [SCOI2005]繁忙的都市 (最小生成树裸题无重边) 超简单写法!!
Description 城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造.城市C的道路是这样分布的:城市中有n个交叉路口,有些交叉路口之间有道路相连,两个交叉路口 ...
- BZOJ 1083:[SCOI2005]繁忙的都市(最小生成树)
1083: [SCOI2005]繁忙的都市 Description 城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造.城市C的道路是这样分布的:城市中有n个交叉路 ...
- BZOJ 1083: [SCOI2005]繁忙的都市 kruskal
1083: [SCOI2005]繁忙的都市 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=1083 Description 城市C是一个非 ...
- BZOJ 1083: [SCOI2005]繁忙的都市(MST)
裸的最小生成树..直接跑就行了 ---------------------------------------------------------------------- #include<c ...
- bzoj 1083 繁忙的都市
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1083 题解: 在bzoj里能遇到如此如此水的题真是不容易…… 乍一看好像有点吓人,其实是一 ...
随机推荐
- CDateTimeUI类源码分析
CDateTimeUI是duilib里选择日期的控件,继承于CLabelUI控件,用于记录已经选择的日期,选择控件则是调用win32的日期选择控件. CDateTimeUI包含两个类,一个是CDate ...
- 阿牛的EOF牛肉串(递推)
阿牛的EOF牛肉串 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Sub ...
- Vue学习(一):Vue实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Qt 蓝牙部分翻译
这是我第一次尝试翻译技术文档,自己英语太烂,一直不敢尝试,感谢生活,让我勇敢迈出这第一步. 大部分都是直译,如有不妥,还请制导. Qt Bluetooth The Bluetooth API prov ...
- C++学习002-C++代码中插入汇编语句
在C++中我们有时会遇到使用汇编语言的情况,这时可以在前面加上关键字“_asm”宏. 如下示例 编写环境 :vs2015 int main() { __asm mov al, 0x20; __asm ...
- [USACO19JAN]Cow Poetry
题面 Solution: 这是一道很好的dp题. 一开始看不懂题面没有一点思路,看了好久题解才看懂题目... \(y[i]\) 为第 \(i\) 个词结尾,\(l[i]\) 为第 \(i\) 个词长度 ...
- SDOI2013森林
题面 主席树启发式合并,每次连边维护并查集,集合大小,求lca所需信息,合并两个树上的主席树, 重点看代码. #include <iostream> #include <algori ...
- Python杂篇
一:文件保存 def save_to_file(file_name, contents): fh = open(file_name, 'w') fh.write(contents) fh.close( ...
- URAL 1741 Communication Fiend(最短路径)
Description Kolya has returned from a summer camp and now he's a real communication fiend. He spends ...
- Java项目启动时候报Neither the JAVA_HOME nor the JRE_HOME environment variable is defined 解决办法
今天在发布Java项目的时候又遇到 Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At leas ...