算法:最短路
求两遍最短路,一个是从起点走向终点,另一个从终点走向起点,记录下每次走每个点的最短路,然后枚举一遍,对于每个点,找一个最大的最短路看能否更新min。
program P1356;
const
maxn=10000;
type
atp=record
y,dis,next:longint;
end;
var
head,tail,n,m,tot,st,ed:longint;
b:array [0..maxn] of boolean;
first,que:array [0..maxn] of longint;
v:array [0..1,0..maxn] of longint;
map:array [0..maxn] of atp;
procedure init;
var
i,x,y,dis:longint;
begin
fillchar(v,sizeof(v),100);
readln(n,m);
for i:=1 to m do
begin
readln(x,y,dis);
inc(tot);
map[tot].y:=y;
map[tot].dis:=dis;
map[tot].next:=first[x];
first[x]:=tot;
inc(tot);
map[tot].y:=x;
map[tot].dis:=dis;
map[tot].next:=first[y];
first[y]:=tot;
end;
readln(st,ed);
end;
procedure SPFA(x:longint);
var
t:longint;
begin
fillchar(b,sizeof(b),false);
fillchar(que,sizeof(que),0);
if x=0 then
begin
v[x,st]:=0;
que[1]:=st;
b[st]:=true;
end
else
begin
v[x,ed]:=0;
que[1]:=ed;
b[ed]:=true;
end;
head:=0;
tail:=1;
while head<tail do
begin
inc(head);
t:=first[que[head]];
while t<>0 do
begin
if v[x,que[head]]+map[t].dis<v[x,map[t].y] then
begin
v[x,map[t].y]:=v[x,que[head]]+map[t].dis;
if not b[map[t].y] then
begin
inc(tail);
que[tail]:=map[t].y;
b[map[t].y]:=true;
end;
end;
t:=map[t].next;
end;
b[que[head]]:=false;
end;
end;
function max(x,y:longint):longint;
begin
if x>y then exit(x) else exit(y);
end;
procedure outit;
var
min,i:longint;
begin
min:=maxlongint;
for i:=1 to n do if max(v[0,i],v[1,i])<min then min:=max(v[0,i],v[1,i]);
if min=v[0,0] then writeln('Peace!') else writeln(min);
end;
begin
assign(input,'P1356.in'); reset(input);
assign(output,'P1356.out'); rewrite(output);
init;
SPFA(0);
SPFA(1);
outit;
close(input); close(output);
end.