比赛 20101110 评测结果 WWWWWWWWWW
题目名称 奶牛派对 最终得分 0
用户昵称 nick09 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-10 21:37:56
显示代码纯文本
program party;
var n,m,x,i,j,sum,ans:longint;
p:array[1..2,0..1000,0..1000]of longint;
d:array[1..2,0..1000]of longint;
v:array[0..100000]of boolean;
procedure init;
var a,b,c:longint;
begin
assign(input,'party.in');reset(input);
assign(output,'party.out');rewrite(output);
readln(n,m,x);
for i:=1 to n do
  for j:=1 to n do
    begin
     p[1,i,j]:=-1;
     p[2,i,j]:=-1;
     end;
for i:=1 to m do
  begin
  readln(a,b,c);
  if p[1,a,b]>c then begin  p[1,a,b]:=c;p[2,b,a]:=c;end;
  end;
end;

procedure go(k:longint);
var
min,minj,i,j,t:longint;
begin
fillchar(v,sizeof(v),false);
for i:=1 to n do
 if p[k,x,i]<>-1 then d[k,i]:=p[k,x,i]
else d[k,i]:=-1;
v[x]:=true;
d[k,x]:=0;
for i:=n-1 downto 1 do
  begin
  min:=-1;
  for j:=1 to n do
  if ((d[k,j]<min)or(min=-1))and(not v[j])then
          begin min:=d[k,j];minj:=j;end;
  if min<>-1 then
    begin
    j:=minj;
    for t:=1 to n do
      if (d[k,j]+p[k,j,t]<d[k,t])and(not v[t]) then
         d[k,t]:=d[k,j]+p[k,j,t];
    end;
  end;
end;

Begin
init;
go(1);

go(2);
ans:=0;
for i:=1 to n do
  begin
  sum:=d[1,i]+d[2,i];
if (sum>ans)and(i<>x) then ans:=sum;
  end;
writeln(ans);
close(input);close(output);
end.