2013-09-08 09:48

最大生成树,输出生成树中最短的边儿即可

或者对边儿排序,二份答案+BFS判断是否1连通N

时间复杂度都是O(NlogN)的

附最大生成树pascal代码

//By BLADEVIL
var
m, n, t :longint;
pre, other, len :array[0..101000] of longint;
father :array[0..100100] of longint;
i :longint; procedure init;
var
i :longint;
x, y, z :longint;
begin
read(n,m);
for i:=1 to m do
begin
read(x,y,z);
pre[i]:=x;
other[i]:=y;
len[i]:=z;
end;
for i:=1 to n do father[i]:=i;
end; procedure qs(low,high:longint);
var
i, j, x, z :longint;
begin
i:=low; j:=high; x:=len[(i+j) div 2];
while i<j do
begin
while x>len[j] do dec(j);
while x<len[i] do inc(i);
if i<=j then
begin
z:=len[i]; len[i]:=len[j]; len[j]:=z;
z:=pre[i]; pre[i]:=pre[j]; pre[j]:=z;
z:=other[i]; other[i]:=other[j]; other[j]:=z;
inc(i); dec(j);
end;
end;
if i<high then qs(i,high);
if j>low then qs(low,j);
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
j :longint;
a, b :longint;
begin
init;
qs(1,m);
for j:=1 to m do
begin
a:=getfather(pre[j]);
b:=getfather(other[j]);
if a<>b then father[b]:=a;
a:=getfather(1);
b:=getfather(n);
if a=b then
begin
writeln('Scenario #',i,':');
writeln(len[j]);
writeln;
exit;
end;
end;
end; begin
read(t);
for i:=1 to t do main;
end.

  

poj 1797的更多相关文章

  1. POJ 1797 Heavy Transportation (Dijkstra变形)

    F - Heavy Transportation Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & ...

  2. poj 1797 Heavy Transportation(最大生成树)

    poj 1797 Heavy Transportation Description Background Hugo Heavy is happy. After the breakdown of the ...

  3. POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径)

    POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径) Description Background Hugo ...

  4. POJ.1797 Heavy Transportation (Dijkstra变形)

    POJ.1797 Heavy Transportation (Dijkstra变形) 题意分析 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d, ...

  5. POJ 1797 ——Heavy Transportation——————【最短路、Dijkstra、最短边最大化】

    Heavy Transportation Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64 ...

  6. Heavy Transportation POJ 1797 最短路变形

    Heavy Transportation POJ 1797 最短路变形 题意 原题链接 题意大体就是说在一个地图上,有n个城市,编号从1 2 3 ... n,m条路,每条路都有相应的承重能力,然后让你 ...

  7. POJ 1797 Heavy Transportation (最大生成树)

    题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...

  8. POJ 1797 Heavy Transportation (Dijkstra)

    题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...

  9. poj 1797(并查集)

    http://poj.org/problem?id=1797 题意:就是从第一个城市运货到第n个城市,最多可以一次运多少货. 输入的意思分别为从哪个城市到哪个城市,以及这条路最多可以运多少货物. 思路 ...

  10. Poj(1797) Dijkstra对松弛条件的变形

    题目链接:http://poj.org/problem?id=1797 题意:从路口1运货到路口n,最大的运货重量是多少?题目给出两路口间的最大载重. 思路:j加到s还是接到K下面,取两者的较大者,而 ...

随机推荐

  1. Thinkphp5使用validate实现验证功能

    作为前端er,对于验证这块有着切身的体会,虽然逐渐得心应手,但始终没有一个内置的功能拿来就能用.tp5恰好提供一个.本文简单介绍并实现以下.主要是实现一下. 验证的实现基于tp5内置的对象valida ...

  2. 第一次通过CLR Profile解决内存占用过高的问题

    炮哥:"嘿,哥们,忙啥呢,电脑卡成这逼样." 勇哥:"在用CLR Profile工具分析下FlexiPrint的内存占用情况." 炮哥:“哎哟,不错啊,玩高级的 ...

  3. BZOJ 1050 旅行(并查集)

    很好的一道题.. 首先把边权排序.然后枚举最小的边,再依次添加不小于该边的边,直到s和t联通.用并查集维护即可. # include <cstdio> # include <cstr ...

  4. Python 开篇及第一个Python程序

    本节内容 python 简单介绍 python 2.x 或者python 3.x python 安装 第一个python程序 一.python简单介绍 python的创始人为吉多.范罗苏姆(Guido ...

  5. vue2.0 自定义时间过滤器

    html <td>{{serverInfo.serverTime| formatTime('YMDHMS')}}</td> js serverTime: new Date(). ...

  6. Docker-端口映射

    Docker-端口映射 Docker端口映射 docker容器在启动的时候,如果不指定端口映射参数,在容器外部是无法通过网络来访问容器内的网络应用和服务的. 亦可使用Dockerfile文件中的EXP ...

  7. [zhuan]Android程序的真正入口Application

    http://blog.csdn.net/coding_or_coded/article/details/6602560 接触android已经有一段时间了,一直以为android程序的入口是配置文件 ...

  8. ubuntu16.04装chrome

    --更简单的方法是先下载chromium浏览器,这是不禁止的,然后打开chromium搜索chrome,chrome的官网下载即可   //安装好后,终端输入google-chrome即可打开 另一种 ...

  9. noip模拟赛 但有用

    题目描述 给定一个 n ∗ m 个矩阵,矩阵中每个数都是 [1, 12] 内的整数.你可以执行下列两个操作任意多次: • 指定一行,将该行所有数字 +1. • 指定一列,将该列所有数字 +1. 如果执 ...

  10. Makefile中的 =,:=,?=,+= 的差异

    在Makefile中常常遇见这几种等操作,总结一下具体区别. =  是最基本的赋值 :=  是用右值覆盖左值 ?=  判断,如果左值没有被赋值过就赋以右值,否则,不做赋值动作 += 在左值后面连接右值 ...