比赛 |
20101110 |
评测结果 |
AAAAAAAAAA |
题目名称 |
奶牛派对 |
最终得分 |
100 |
用户昵称 |
maxiem |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-11-10 20:43:49 |
显示代码纯文本
program party;
var
dist,table,map:array [1..1000,0..1000] of longint;
q:array [0..100000] of longint;
f:array [1..1000] of boolean;
max,i,j,n,m,x,a,b,v,head,tail:longint;
procedure spfa;
var now:longint;
begin
for i:=1 to n do begin
for j:=1 to n do dist[i,j]:=maxlongint;
fillchar (f,sizeof(f),0);
dist[i,i]:=0;f[i]:=true;q[1]:=i;
head:=1;tail:=1;
while head<=tail do begin
now:=q[head];
for j:=1 to map[now,0] do begin
if dist[i,map[now,j]]>dist[i,now]+table[now,map[now,j]] then begin
dist[i,map[now,j]]:=dist[i,now]+table[now,map[now,j]];
if f[map[now,j]]=false then begin
tail:=(tail+1) mod m;
q[tail]:=map[now,j];
f[map[now,j]]:=true;
end;
end;
end;
f[now]:=false;
head:=(head+1) mod m;
end;
end;
end;
begin
assign (input,'party.in');
reset (input);
readln (n,m,x);
fillchar (map,sizeof(map),0);
for i:=1 to n do for j:=1 to n do table[i,j]:=maxlongint;
for i:=1 to m do begin
readln (a,b,v);
if v<table[a,b] then table[a,b]:=v;
end;
for i:=1 to n do for j:=1 to n do if table[i,j]<>maxlongint then begin
inc(map[i,0]);
map[i,map[i,0]]:=j;
end;
close (input);
assign (output,'party.out');
rewrite (output);
fillchar (q,sizeof(q),0);
spfa;
max:=0;
for i:=1 to n do if dist[i,x]+dist[x,i]>max then max:=dist[i,x]+dist[x,i];
writeln (max);
close (output);
end.