程序博客网 > 阿里云io优化
来源:互联网 发布:阿里云io优化 编辑:程序博客网 时间:2024/06/03 07:16
5 7 11 2 53 1 42 4 83 2 35 2 93 4 74 5 6输入说明: 一共有5根废弃的电话线杆。电话线杆1不能直接与电话线杆4、5相连。电话线杆5不能直接与电话线杆1、3相连。其余所有电话线杆间均可拉电话线。电信公司可以免费为FJ连结一对电话线杆。
4输出说明: FJ选择如下的连结方案:1->3;3->2;2->5,这3对电话线杆间需要的电话线的长度分别为4、3、9。FJ让电信公司提供那条长度为9的电话线,于是,他所需要购买的电话线的最大长度为4。
数据范围限制
uses math;var a,b,c,d,i,j,k,maw:longint; v:array[1..1000,1..1000]of longint; f:array[1..1000,1..1000]of longint; p:array[1..1000]of boolean; u:longint; po:boolean;procedure pd(s:longint);var i,ma,mi:longint;begin if po=false then exit; p[s]:=false; ma:=maxlongint; for i:=1 to a do begin if (p[i]=true)then begin f[1,i]:=min(f[1,s]+f[s,i],f[1,i]); if (f[1,i]<=ma)and(p[i]=true) then begin ma:=f[1,i]; mi:=i; end; end; end; inc(u); if u=a then begin po:=false; exit; end; pd(mi); if po=false then exit;end;procedure ss(l,r:longint);var mid,i,j:longint;begin if (l=r) then begin writeln(l); halt; end; mid:=(l+r) div 2; for i:=1 to 1000 do begin for j:=1 to 1000 do begin if v[i,j]=2139062143 then begin f[i,j]:=maxlongint div 3; end else if v[i,j]>mid then f[i,j]:=1 else if v[i,j]<=mid then f[i,j]:=0; end; end; fillchar(p,sizeof(p),true); u:=1; po:=true; f[1,1]:=0; pd(1); if f[1,a]=maxlongint div 3 then begin writeln(-1); halt; end; if f[1,a]<=c then ss(l,mid) else ss(mid+1,r);end;begin assign(input,'phoneline.in');reset(input); assign(output,'phoneline.out');rewrite(output); //assign(input,'1.in');reset(input); read(a,b,c); fillchar(v,sizeof(v),127); for d:=1 to b do begin readln(i,j,k); v[i,j]:=k; v[j,i]:=k; maw:=max(maw,k); end; ss(0,maw); close(input); close(output);end.