比赛 |
20101110 |
评测结果 |
AAAAAAAAAA |
题目名称 |
奶牛派对 |
最终得分 |
100 |
用户昵称 |
donny |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-11-10 19:14:22 |
显示代码纯文本
program sparty;
var
i,j,k:longint;
n,m,s:longint;
a:array[1..1000,1..1000]of longint;
a1,a2:array[1..1000]of longint;
f:array[0..100000]of longint;
o,p,q:longint;
max:longint;
procedure spfa1;
var
i:longint;
head,tail:longint;
begin
head:=1;
tail:=1;
while head<=tail do
begin
for i:=1 to n do
if a1[f[head]]+a[f[head],i]<a1[i] then
begin
a1[i]:=a1[f[head]]+a[f[head],i];
inc(tail);
f[tail]:=i;
end;
inc(head);
end;
end;
procedure spfa2;
var
i:longint;
head,tail:longint;
begin
head:=1;
tail:=1;
while head<=tail do
begin
for i:=1 to n do
if a2[f[head]]+a[i,f[head]]<a2[i] then
begin
a2[i]:=a2[f[head]]+a[i,f[head]];
inc(tail);
f[tail]:=i;
end;
inc(head);
end;
end;
begin
assign(input,'party.in');
reset(input);
assign(output,'party.out');
rewrite(output);
readln(n,m,s);
for i:=1 to n do
for j:=1 to n do
a[i,j]:=236549210;
for i:=1 to n do
a[i,i]:=0;
for i:=1 to m do
begin
read(o,p);
readln(a[o,p]);
end;
f[0]:=1;
f[1]:=s;
for i:=1 to n do
a1[i]:=maxint;
a1[s]:=0;
spfa1;
f[1]:=s;
for i:=1 to n do
a2[i]:=maxint;
a2[s]:=0;
spfa2;
for i:=1 to n do
if a1[i]+a2[i]>max then
max:=a1[i]+a2[i];
writeln(max);
close(input);
close(output);
end.