比赛 20120418s 评测结果 AAAAAAAAAA
题目名称 捉迷藏 最终得分 100
用户昵称 wo shi 刘畅 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2012-04-18 08:55:56
显示代码纯文本
  1. var
  2. n,m,total,i,x,y,min,max,ans:longint;
  3. v:array[0..1000000]of boolean;
  4. point,next,first,d,q:array[0..3000000]of longint;
  5.  
  6. procedure addpage(x,y:longint);
  7. begin
  8. inc(total);
  9. point[total]:=y;
  10. next[total]:=first[x];
  11. first[x]:=total;
  12. end;
  13.  
  14. procedure spfa;
  15. var
  16. i,h,t:longint;
  17. begin
  18. for i:=1 to n do d[i]:=maxlongint div 2;
  19. d[1]:=0;
  20. t:=1;
  21. q[1]:=1;
  22. v[1]:=true;
  23. h:=0;
  24. while h<>t do
  25. begin
  26. h:=(h mod n)+1;
  27. x:=q[h];
  28. i:=first[x];
  29. v[x]:=false;
  30. while i>0 do
  31. begin
  32. y:=point[i];
  33. if d[x]+1<d[y] then
  34. begin
  35. d[y]:=d[x]+1;
  36. if not v[y] then
  37. begin
  38. t:=(t mod n)+1;
  39. q[t]:=y;
  40. v[y]:=true;
  41. end;
  42. end;
  43. i:=next[i];
  44. end;
  45. end;
  46. end;
  47.  
  48. begin
  49. assign(input,'hideseek.in'); reset(input);
  50. assign(output,'hideseek.out'); rewrite(output);
  51. readln(n,m);
  52. for i:=1 to m do
  53. begin
  54. readln(x,y);
  55. addpage(x,y);
  56. addpage(y,x);
  57. end;
  58. spfa;
  59. max:=-maxlongint;
  60. ans:=0;
  61. min:=maxlongint;
  62. for i:=2 to n do
  63. begin
  64. if d[i]>max then
  65. begin
  66. max:=d[i];
  67. ans:=1;
  68. min:=i;
  69. end
  70. else if d[i]=max then inc(ans);
  71. end;
  72. writeln(min,' ',max,' ',ans);
  73. close(input);
  74. close(output);
  75. end.