fork download
  1. uses math;
  2.  
  3. type graph=^node;
  4. node=record
  5. u,v,w:longint;
  6. link:graph;
  7. end;
  8.  
  9. const maxc=round(1e9);
  10.  
  11. var s,t,m,d,n:longint;
  12. fi,fo:text;
  13. queue,trace,like,f:array[0..550]of longint;
  14. inque:array[0..550]of boolean;
  15. // a:array[0..550,0..550]of longint;
  16. g:array[1..550]of graph;
  17. procedure add(u,v,w:longint);
  18. var p:graph;
  19. begin
  20. new(p);
  21. p^.u:=u;
  22. p^.v:=v;
  23. p^.w:=w;
  24. p^.link:=g[u];
  25. g[u]:=p;
  26. end;
  27.  
  28. function fordbellman(s,t:longint):longint;
  29. var d,c,u,v:longint;
  30. p:graph;
  31. begin
  32. d:=0; c:=0; Queue[0]:=s;
  33. // fillchar(inque,sizeof(inque),false);
  34. for v:=0 to n do
  35. begin
  36. f[v]:=maxc;
  37. inque[v]:=false;
  38. end;
  39. inque[s]:=true;
  40. f[s]:=0;
  41. While d<>(c+1) mod n do
  42. Begin
  43. u:=queue[d];
  44. inque[u]:=false;
  45. d:=(d+1) mod n;
  46. // For v:=1 to n do
  47. // if a[u,v]<>0 then
  48. p:=g[u];
  49. while p<>nil do
  50. begin
  51. v:=p^.v;
  52. If f[v] > f[u] + p^.w then
  53. Begin
  54. f[v]:=f[u] + p^.w;
  55. trace[v]:=u;
  56. If not inque[v] then
  57. Begin
  58. c:=(c + 1) mod n;
  59. queue[c]:=v;
  60. inque[v]:=true;
  61. end;
  62. end;
  63. p:=p^.link;
  64. end;
  65. End;
  66. exit(f[t]);
  67. end;
  68.  
  69. procedure process;
  70. var i,kq,j,luu,t:longint;
  71. begin
  72. kq:=maxlongint;
  73. for i:=1to n do
  74. begin
  75. t:=0;
  76. for j:=1to m do
  77. if i<>like[j] then
  78. t:=t+fordbellman(i,like[j]);
  79. if kq>t then
  80. begin
  81. kq:=t;
  82. luu:=i;
  83. end;
  84. end;
  85. write(fo,luu);
  86. end;
  87.  
  88. procedure enter;
  89. var u,v,i,j,w:longint;
  90. begin
  91. readln(fi,n,m,s);
  92. for i:=1to m do readln(fi,like[i]);
  93. for j:=1to s do
  94. begin
  95. readln(fi,u,v,w);
  96. add(u,v,w);
  97. add(v,u,w);
  98. end;
  99. close(fi);
  100. end;
  101.  
  102. begin
  103. assign(fi,'');reset(fi);
  104. assign(fo,'');rewrite(fo);
  105. enter;
  106. process;
  107. close(fo);
  108. end.
  109.  
  110.  
Success #stdin #stdout 0s 412KB
stdin
Standard input is empty
stdout
134603849