题意:给出一个无向图,求一条1~2的路径使得路径上的最大边权最小.
分析:dijkstra变形,将更新距离的过程改为取最大值即可.
code:
const maxn=201; var d:array[0..maxn,0..maxn] of extended; x,y:array[0..maxn] of longint; v:array[0..maxn] of boolean; n,s,t,i,j,p,casenum:longint; minx:extended; function calc(a,b:longint):extended; begin calc:=sqrt(sqr(x[a]-x[b])+sqr(y[a]-y[b])); end; function max(a,b:extended):extended; begin if a>b then exit(a); exit(b); end; function min(a,b:extended):extended; begin if a>b then exit(b); exit(a); end; begin while not seekeof do begin readln(n); if n=0 then break; inc(casenum); for i:=1 to n do readln(x[i],y[i]); readln; for i:=1 to n-1 do for j:=i+1 to n do begin d[i,j]:=calc(i,j); d[j,i]:=d[i,j]; end; fillchar(v,sizeof(v),0); s:=1; t:=2; v[s]:=true; for j:=2 to n do begin minx:=1e10; for i:=1 to n do if (not v[i])and(d[s,i]<>0)and(d[s,i]<minx) then begin minx:=d[s,i]; p:=i; end; v[p]:=true; for i:=1 to n do if (d[s,p]<>0)and(d[p,i]<>0) then d[s,i]:=min(d[s,i],max(d[s,p],d[p,i])); end; writeln('Scenario #',casenum); writeln('Frog Distance = ',d[1,2]:0:3); writeln; end; end.