首页 > 其他分享 >POJ 1125(Floyd)

POJ 1125(Floyd)

时间:2022-10-25 12:34:54浏览次数:55  
标签:do begin end read 1125 Floyd POJ ans NULL


裸Floyd


Program P1125;
const
maxn=100;
maxedge=10;
NULL=-2139062144;
var
n,i,j,k,m,v,t,ans:longint;
f:array[1..maxn,1..maxn] of longint;
function max(a,b:longint):longint;
begin
if a<b then exit(b) else exit(a);
end;
begin
read(n);
while (n<>0) do
begin
fillchar(f,sizeof(f),128);
for i:=1 to n do
begin
f[i,i]:=0;
read(m);
for j:=1 to m do
begin
read(v,t);
f[i,v]:=t;
end;
end;

for k:=1 to n do
for i:=1 to n do
for j:=1 to n do
if (f[i,k]<>NULL) and (f[k,j]<>NULL) then
if (f[i,k]+f[k,j]<f[i,j]) or (f[i,j]=NULL) then f[i,j]:=f[i,k]+f[k,j];
ans:=maxlongint;

v:=0;
for i:=1 to n do
begin
t:=f[i,1];
for j:=1 to n do
begin
if f[i,j]=NULL then break else t:=max(f[i,j],t);
end;
if f[i,j]=NULL then continue;
if t<ans then begin v:=i; ans:=t; end;

end;
if (ans=maxlongint) then writeln('disjoint') else writeln(v,' ',ans);



read(n);
end;
end.



标签:do,begin,end,read,1125,Floyd,POJ,ans,NULL
From: https://blog.51cto.com/u_15724837/5794486

相关文章

  • POJ 1700(过河问题)
    玩过《雷顿》就知道这题可以贪心小等于2人:1,2->3人时:1,3->1<-1,2->1<-否则:1,2->2<-max1,max2->1<-OR:1,max1->1<-2,max2->2<-于是数据规模-2ProgramP1700;vart,n,i,j:long......
  • POJ 3264(STRMQ)
    forj:=1toln(n)/ln(2)  fori:=1ton-(1shlj)+1do    f[i,j]:=min(f[i,j-1],f[i+(1shl(j-1),j-1];f[l,r]:=min(f[l,j],f[r-(1shlj)+1,j];j=ln(r-l+1......
  • POJ 3748(C++的16进制读法 %x)
    P党写几小时的程序C++才几行……首先P的位运算有上限2^30此时即便是int64也会因为补码坑死人的到1shl31时 int64是负数故这个时候不能shr为多出好多位造成以......
  • POJ 2185(最大平铺矩阵)
    DefaultMilkingGridDescription(1<=R<=10,000) *C (1<=C<=75) 的矩阵,求它的最大平铺矩阵,不够的地方可部分平铺,但不可重叠。Input......
  • POJ 3661(贝茜晨练)
    经典Dp,果断记忆化……#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<functional>usingnamespacestd;#defineMAXN10000+10#defineM......
  • POJ 3575(计算几何与二分-无尽的小数处理)
    这题写了将近半个月……总是在D各种Bug总的说来-这题最难应该是在精度处理上11001这组数据过了就说明精度处理差不多了……Programkingdom;constmaxn=100;maxm=10......
  • POJ 3049(输出字母)
    果断搜ProgramP3049;varn,i,j,m:longint;a:array[1..26]ofchar;b:array['a'..'z']ofboolean;c:char;procedureswap(vara,b:char);vart:char;begin......
  • POJ 3289(高精度乘法)
    高精度乘法ProgramP3289;constmaxn=40000;F=10;typearr=recordd:array[1..maxn]oflongint;len,doc:longint;end;varr,m:arr;y:long......
  • POJ 1222(Gauss消元xor版)
    EXTENDEDLIGHTSOUTDescriptionLightsOut就是下图的游戏,给你一个5*6的矩阵. 你的目标是把灯全关上. 0表示关,1表示开.Input第一行为数据......
  • POJ 2398(二分点集)
    DefaultToyStorageDescription在长方形(x1,y1)(x2,y2)中有n块板(保证与上下边相交),和m个点。现给出板和点的位置,求拥有相同点数的区域数、  Inpu......