记录编号 9974 评测结果 AWWWWTTTTT
题目名称 公路修建 最终得分 10
用户昵称 Gravatar苏轼 是否通过 未通过
代码语言 Pascal 运行时间 5.228 s
提交时间 2009-04-23 12:51:12 内存使用 171.78 MiB
显示代码纯文本
  1. {
  2. haoi2009 moni3 t2
  3. time:2009.4.23
  4. rp++
  5. }
  6. program cch(input,output);
  7. const
  8. maxf=10000000;
  9. var
  10. fa:array[1..5000] of longint;
  11. n:longint;
  12. map:array[1..5000,1..5000] of real;
  13. v:array[1..5000] of boolean;
  14.  
  15. procedure init;
  16. var
  17. i,j:longint;
  18. x,y:array[1..5000] of real;
  19. begin
  20. assign(input,'roadz.in');
  21. assign(output,'roadz.out');
  22. reset(input);
  23. rewrite(output);
  24. readln(n);
  25. for i:=1 to n do
  26. readln(x[i],y[i]);
  27. for i:=1 to n do
  28. for j:=1 to n do
  29. map[i,j]:=sqrt(sqr(x[i]-x[j])+sqr(y[i]-y[j]));
  30. end;
  31.  
  32. function getfather(k:longint):longint;
  33. begin
  34. if k=fa[k] then exit(k);
  35. fa[k]:=getfather(fa[k]);
  36. exit(fa[k]);
  37. end;
  38.  
  39. procedure main;
  40. var
  41. i,j,f,p,k,fi,fj,ch:longint;
  42. a:array[1..5000] of longint;
  43. dis,ans,min:real;
  44. begin
  45. for i:=1 to n do fa[i]:=i;
  46. repeat
  47. for i:=1 to n do a[i]:=0;
  48. for f:=1 to n do
  49. begin
  50. dis:=maxf;
  51. for i:=1 to n do
  52. if getfather(i)=f then
  53. for j:=1 to n do
  54. if i<>j then
  55. begin
  56. fi:=getfather(i);
  57. fj:=getfather(j);
  58. if (fi<>fj)and(a[j]<>i) then
  59. begin
  60. if dis>map[i,j] then
  61. begin
  62. dis:=map[i,j];
  63. k:=j; p:=i;
  64. end
  65. end;
  66. end;
  67. if dis<maxf then
  68. begin ans:=ans+dis;
  69. a[p]:=k;
  70. end;
  71. end;
  72. for i:=1 to n do v[i]:=true;
  73. for i:=1 to n do
  74. if a[i]<>0 then
  75. fa[getfather(i)]:=getfather(a[i]);
  76. for i:=1 to n do
  77. if v[i] and (a[i]<>0) then
  78. begin
  79. j:=i; min:=0;
  80. repeat
  81. if min<map[j,a[j]] then
  82. min:=map[j,a[j]];
  83. j:=a[j];
  84. if v[j]=true then v[j]:=false
  85. else break;
  86. until (j=i)or(j=0);
  87. if (min<>0)and(j=i) then ans:=ans-min;
  88. end;
  89. ch:=0;
  90. for i:=1 to n do
  91. if getfather(i)=getfather(1) then inc(ch);
  92. until ch=n;
  93. writeln(ans:0:2);
  94. close(input);
  95. close(output);
  96. end;
  97.  
  98. begin
  99. init;
  100. main;
  101. end.