比赛 20101110 评测结果 EEEEEEEEEE
题目名称 奶牛派对 最终得分 0
用户昵称 belong.zmx 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-10 19:13:29
显示代码纯文本
program sparty(input,output);
var
 a:array[1..1000,1..1000]of longint;
 q:array[1..100000]of longint;
 f1,f2:array[1..1000]of longint;
 t:array[0..1000]of boolean;
 n,m,x:longint;
 ans:longint;
 i,j,u,y,o:longint;

procedure spfa1;
var
 i,j:longint;
 head,tail:longint;
begin
 head:=1;
 tail:=1;
 q[head]:=x;
 f1[q[head]]:=0;
 t[q[head]]:=true;
 repeat
  for i:=1 to n do
   if (a[q[head],i]<>maxlongint)and(a[q[head],i]+f1[q[head]]<f1[i]) then
   begin
    if t[i]=false then
    begin
     inc(tail);
     f1[i]:=a[q[head],i]+f1[q[head]];
     t[i]:=true;
     q[tail]:=i;
    end
    else
    begin
     f1[i]:=a[q[head],i]+f1[q[head]];
    end;
   end;
  inc(head);
  t[q[head]]:=false;
 until head>tail;
 for i:=1 to tail do q[i]:=0;
 for i:=1 to n do t[i]:=false;
end;

procedure spfa2;
var
 i,j:longint;
 head,tail:longint;
begin
 head:=1;
 tail:=1;
 q[head]:=x;
 f2[q[head]]:=0;
 t[q[head]]:=true;
 repeat
  for i:=1 to n do
   if (a[i,q[head]]<>maxlongint)and(a[i,q[head]]+f2[q[head]]<f2[i]) then
   begin
    if t[i]=false then
    begin
     inc(tail);
     f2[i]:=a[i,q[head]]+f2[q[head]];
     t[i]:=true;
     q[tail]:=i;
    end
    else
    begin
     f2[i]:=a[i,q[head]]+f2[q[head]];
    end;
   end;
  inc(head);
  t[q[head]]:=false;
 until head>tail;
end;

begin
 assign(input,'sparty.in');
 reset(input);
 readln(n,m,x);
 for i:=1 to n do
  for j:=1 to n do a[i,j]:=maxlongint;
 for i:=1 to m do
 begin
  readln(u,y,o);
  a[u,y]:=o;
 end;
 close(input);

 for i:=1 to n do
 begin
  f1[i]:=maxlongint;
  f2[i]:=maxlongint;
 end;

 spfa1;
 spfa2;

 for i:=1 to n do
  if f1[i]+f2[i]>ans then ans:=f1[i]+f2[i];

 assign(output,'sparty.out');
 rewrite(output);
 writeln(ans);
 close(output);
end.