比赛 20101110 评测结果 AAAAAAAAAA
题目名称 奶牛派对 最终得分 100
用户昵称 wo shi 刘畅 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-10 19:53:36
显示代码纯文本
  1. var
  2. n,m,p,x,y,i,j,max:longint;
  3. f,g:array[0..1000,0..1000]of longint;
  4. w,e:array[0..1000]of boolean;
  5. a,b:array[0..1001]of longint;
  6.  
  7. procedure djs1;
  8. var
  9. i,j,s,h,d,ma:longint;
  10. begin
  11. w[p]:=true;
  12. s:=1;
  13. d:=p;
  14. while s<n do
  15. begin
  16. inc(s);
  17. h:=0;
  18. ma:=maxlongint;
  19. for i:=1 to n do
  20. if (not w[i]) then
  21. begin
  22. if a[d]+f[d,i]<a[i] then
  23. a[i]:=a[d]+f[d,i];
  24. if a[i]<ma then
  25. begin
  26. ma:=a[i];
  27. h:=i;
  28. end;
  29. end;
  30. w[h]:=true;
  31. d:=h;
  32. end;
  33. end;
  34.  
  35. procedure djs2;
  36. var
  37. i,j,s,d,h,ma:longint;
  38. begin
  39. e[p]:=true;
  40. s:=1;
  41. d:=p;
  42. while s<n do
  43. begin
  44. inc(s);
  45. ma:=maxlongint;
  46. for i:=1 to n do
  47. if not e[i] then
  48. begin
  49. if b[d]+g[d,i]<b[i] then
  50. b[i]:=b[d]+g[d,i];
  51. if b[i]<ma then
  52. begin
  53. ma:=b[i];
  54. h:=i;
  55. end;
  56. end;
  57. e[h]:=true;
  58. d:=h;
  59. end;
  60. end;
  61.  
  62. begin
  63. assign(input,'party.in'); reset(input);
  64. assign(output,'party.out'); rewrite(output);
  65. readln(n,m,p);
  66. for i:=1 to n do
  67. for j:=1 to n do
  68. begin
  69. f[i,j]:=10000000;
  70. g[i,j]:=10000000;
  71. end;
  72. for i:=1 to n do
  73. begin
  74. a[i]:=10000000;
  75. b[i]:=10000000;
  76. end;
  77. for i:=1 to m do
  78. begin
  79. readln(x,y,f[x,y]);
  80. if x=p then a[y]:=f[x,y];
  81. g[y,x]:=f[x,y];
  82. if y=p then b[x]:=g[y,x];
  83. end;
  84. djs1;
  85. djs2;
  86. max:=-maxlongint;
  87. for i:=1 to n do
  88. begin
  89. if (a[i]<10000000)and(b[i]<10000000)
  90. and(a[i]+b[i]>max) then
  91. max:=a[i]+b[i];
  92. end;
  93. writeln(max);
  94. close(input);
  95. close(output);
  96. end.