比赛 20101110 评测结果 AAAAAAAAAA
题目名称 奶牛派对 最终得分 100
用户昵称 Achilles 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-10 20:30:36
显示代码纯文本
program party;
var
  n,m,x,i,j,a,b,c,min,p:longint;
  tab1,tab2:array[1..1000,1..1000]of longint;
  min1,min2:array[1..1000]of longint;
  hx:array[1..1000]of boolean;
begin
  assign(input,'party.in');
  assign(output,'party.out');
  reset(input);
  rewrite(output);
  readln(n,m,x);
  for i:=1 to n do
    for j:=1 to n do
    begin
      tab1[i,j]:=2000000000;
      tab2[i,j]:=2000000000;
    end;
  for i:=1 to m do
  begin
    readln(a,b,c);
    tab1[a,b]:=c;
    tab2[b,a]:=c;
  end;
  for i:=1 to n do
  begin
    min1[i]:=tab1[x,i];
    min2[i]:=tab2[x,i];
  end;
  fillchar(hx,sizeof(hx),true);
  hx[x]:=false;
  for i:=1 to n do
  begin
    min:=2000000000;
    for j:=1 to n do
      if (tab1[x,j]<min)and(hx[j]) then begin
        min:=tab1[x,j];
        p:=j;
      end;
    hx[p]:=false;
    for j:=1 to n do
      if (hx[j])and(tab1[p,j]+min1[p]<min1[j]) then begin
        min1[j]:=tab1[p,j]+min1[p];
        tab1[x,j]:=min1[j];
      end;
  end;
  fillchar(hx,sizeof(hx),true);
  hx[x]:=false;
  for i:=1 to n do
  begin
    min:=2000000000;
    for j:=1 to n do
      if (tab2[x,j]<min)and(hx[j]) then begin
        min:=tab2[x,j];
        p:=j;
      end;
    hx[p]:=false;
    for j:=1 to n do
      if (hx[j])and(tab2[p,j]+min2[p]<min2[j]) then begin
        min2[j]:=tab2[p,j]+min2[p];
        tab2[x,j]:=min2[j];
      end;
  end;
  min:=0;
  for i:=1 to n do
    if i<>x then begin
      if (min1[i]+min2[i]>min)and(min1[i]<>2000000000)and(min2[i]<>2000000000) then min:=min1[i]+min2[i];
    end;
  writeln(min);
  close(input);
  close(output);
end.