记录编号 21513 评测结果 AAAAAAAAAA
题目名称 奶牛派对 最终得分 100
用户昵称 GravatarDes. 是否通过 通过
代码语言 Pascal 运行时间 0.114 s
提交时间 2010-11-11 09:02:55 内存使用 3.94 MiB
显示代码纯文本
program party;
var disa,disb:array[1..1000]of longint;
    a:array[1..1000,1..1000]of longint;
    q,bo:array[1..1000]of longint;
    t,k,m,n,i,j,x,y,max:longint;
begin
assign(input,'party.in');
reset(input);
assign(output,'party.out');
rewrite(output);
readln(n,m,x);
{for t:=1 to 1000 do
  for k:=1 to 1000 do
    a[t,k]:maxint;}
fillchar(disa,sizeof(disa),1);
fillchar(disb,sizeof(disb),1);
for t:=1 to m do
  begin
    readln(i,j,k);
    a[i,j]:=k;
  end;
i:=0;
j:=1;
q[j]:=x;
bo[x]:=1;
disa[x]:=0;
repeat
  inc(i);
  for t:=1 to n do
    if a[q[i],t]>0 then
      if disa[t]>disa[q[i]]+a[q[i],t] then
        begin
          disa[t]:=disa[q[i]]+a[q[i],t];
          if bo[t]=0 then
            begin
              inc(j);
              q[j]:=t;
              bo[t]:=1;
            end;
        end;
  bo[q[i]]:=0;
until i=j;
i:=0;
j:=1;
fillchar(bo,sizeof(bo),0);
bo[x]:=1;
disb[x]:=0;
repeat
   inc(i);
  for t:=1 to n do
    if a[t,q[i]]>0 then
      if disb[t]>disb[q[i]]+a[t,q[i]] then
        begin
          disb[t]:=disb[q[i]]+a[t,q[i]];
          if bo[t]=0 then
            begin
              inc(j);
              q[j]:=t;
              bo[t]:=1;
            end;
        end;
  bo[q[i]]:=0;
until i=j;
for t:=1 to n do
  if (disa[t]<>16843009)and(disb[t]<>16843009)and(disa[t]+disb[t]>max) then
    max:=disa[t]+disb[t];
writeln(max);
close(output);
end.