记录编号 39405 评测结果 AAAAAAAAAA
题目名称 三元限制最短路 最终得分 100
用户昵称 Gravatarfuhao 是否通过 通过
代码语言 Pascal 运行时间 0.699 s
提交时间 2012-07-10 13:00:58 内存使用 123.22 MiB
显示代码纯文本
  1. program patha;
  2. const maxn=1001; maxtot=5000000;
  3. var
  4. pre,xx,yy,step,link,next:array[0..maxtot] of longint;
  5. aa,a:array[0..maxn,0..maxn] of longint;
  6. v:array[0..maxn,0..maxn] of boolean;
  7. n,i,x,y,z,tot,m,k,j,l,h,t:longint;
  8. procedure print(k:longint);
  9. begin
  10. if pre[k]=0 then
  11. begin
  12. write(1,' ',yy[k]);
  13. exit;
  14. end;
  15. print(pre[k]);
  16. write(' ',yy[k]);
  17. end;
  18. procedure bfs;
  19. begin
  20. h:=0; t:=0;
  21. for i:=1 to n do
  22. if a[1,i]<>0 then
  23. if not v[1,i] then
  24. begin
  25. inc(t);
  26. xx[t]:=1; yy[t]:=i; step[t]:=1;
  27. pre[t]:=0;
  28. v[1,i]:=true;
  29. if yy[t]=n then
  30. begin
  31. writeln(step[t]);
  32. print(t);
  33. close(input); close(output);
  34. halt;
  35. end;
  36. end;
  37. repeat
  38. h:=h+1;
  39. i:=a[xx[h],yy[h]];
  40. while i<>0 do
  41. begin
  42. if not v[yy[h],link[i]] then
  43. begin
  44. v[yy[h],link[i]]:=true;
  45. inc(t); pre[t]:=h;
  46. xx[t]:=yy[h]; yy[t]:=link[i];
  47. step[t]:=step[h]+1;
  48. if yy[t]=n then
  49. begin
  50. writeln(step[t]);
  51. print(t);
  52. close(input); close(output);
  53. halt;
  54. end;
  55. end;
  56. i:=next[i];
  57. end;
  58. until h>=t;
  59. end;
  60. procedure insert(x,y:longint);
  61. begin
  62. inc(aa[x,0]); aa[x,aa[x,0]]:=y;
  63. end;
  64. procedure delete(x,y,z:longint);
  65. var i,fa:longint;
  66. begin
  67. i:=a[x,y];
  68. if link[i]=z then
  69. begin
  70. a[x,y]:=next[i];
  71. exit;
  72. end;
  73. fa:=i;
  74. while i<>0 do
  75. begin
  76. if link[i]=z then
  77. begin
  78. next[fa]:=next[i];
  79. exit;
  80. end;
  81. fa:=i;
  82. i:=next[i];
  83. end;
  84. end;
  85. procedure init(x,y,z:longint);
  86. begin
  87. inc(tot); next[tot]:=a[x,y];
  88. a[x,y]:=tot; link[tot]:=z;
  89. end;
  90. begin
  91. assign(input,'patha.in'); reset(input);
  92. assign(output,'patha.out'); rewrite(output);
  93. readln(n,m,k);
  94. fillchar(aa,sizeof(aa),0);
  95. for i:=1 to m do
  96. begin
  97. readln(x,y);
  98. insert(x,y);
  99. insert(y,x);
  100. end;
  101. fillchar(xx,sizeof(xx),0);
  102. yy:=xx; link:=yy;
  103. for i:=1 to n do
  104. for j:=1 to aa[i,0] do
  105. for l:=1 to aa[aa[i,j],0] do
  106. init(i,aa[i,j],aa[aa[i,j],l]);
  107. for i:=1 to k do
  108. begin
  109. readln(x,y,z);
  110. delete(x,y,z);
  111. end;
  112. bfs;
  113. close(input); close(output);
  114. end.