比赛 20120710 评测结果 AAAAAAAAAA
题目名称 三元限制最短路 最终得分 100
用户昵称 SnowDancer 运行时间 0.091 s
代码语言 Pascal 内存使用 112.92 MiB
提交时间 2012-07-10 10:59:26
显示代码纯文本
program patha;
type
  point=^node;
  node=record x:longint;next:point; end;
var
  n,i,j,k,l,m,tot,head,tail,step,tops,now,fa:longint;
  limit:array[1..3000,1..3000] of point;
  visit:array[1..3000,1..3000] of boolean;
  nodes:array[1..150008] of node;
  q,pre:array[1..9000000] of longint;
  h:array[1..3000] of point;
  can:array[1..3000] of boolean;
  stack:array[1..3000] of longint;
  top,p:point;
procedure insertE(u,v:longint);
  begin
    top^.x:=v;top^.next:=h[u];
    h[u]:=top; inc(top);
  end;
procedure print(k:longint);
  begin
    repeat
      inc(tops);
      stack[tops]:=q[k];
      k:=pre[k];
    until q[k]=1;
    writeln(tops);
    write(1);for i:=tops downto 1 do write(' ',stack[i]);writeln;
    close(input); close(output);
    halt;
  end;
begin
  //  OpenFile
  assign(input,'patha.in');reset(input);
  assign(output,'patha.out'); rewrite(output);
  //  Input
  readln(n,m,tot);
  top:=@nodes[1];
  for k:=1 to m do begin
    readln(i,j);
    insertE(i,j);
    insertE(j,i);
  end;
  for l:=1 to tot do begin
    readln(i,j,k);
    top^.x:=k; top^.next:=limit[i,j];
    limit[i,j]:=top;  inc(top);
  end;
  //  BFS
  head:=0; tail:=1;
  q[1]:=1; pre[1]:=1;
  repeat
    inc(head);
    now:=q[head]; fa:=q[pre[head]];
    fillchar(can,sizeof(can),true);
    p:=limit[fa,now];
    while p<>nil do begin
      can[p^.x]:=false;
      p:=p^.next;
    end;
    p:=h[now];
    while p<>nil do begin
      if not visit[now,p^.x] and can[p^.x] then begin
        inc(tail); q[tail]:=p^.x; pre[tail]:=head;
        visit[now,p^.x]:=true;
        if p^.x=n then print(tail);
      end;
      p:=p^.next;
    end;
  until false;
end.