记录编号 14707 评测结果 AAAAAAAAAA
题目名称 [USACO Oct09] 热浪 最终得分 100
用户昵称 GravatarReimBurSe. 是否通过 通过
代码语言 Pascal 运行时间 0.509 s
提交时间 2009-11-03 15:23:05 内存使用 47.82 MiB
显示代码纯文本
  1. Program heatwvx;
  2.  
  3. Type
  4. sc=array [1..2500,0..2500] of longint;
  5. sc1=array [1..2500] of boolean;
  6.  
  7. Var
  8. a,s:sc;
  9. panduan:sc1;
  10. i,j:longint;
  11. n,m,q,z:longint;
  12. x,y,k:longint;
  13. min,p:longint;
  14.  
  15. Begin
  16. assign(input,'heatwvx.in');
  17. assign(output,'heatwvx.out');
  18. reset(input);
  19. rewrite(output);
  20. readln(n,m,q,z);
  21. for i:=1 to n do
  22. for j:=0 to n do
  23. a[i,j]:=99999999;
  24. for j:=1 to m do begin
  25. readln(x,y,k);
  26. s[x,0]:=s[x,0]+1;
  27. s[y,0]:=s[y,0]+1;
  28. s[x,y]:=k;
  29. s[y,x]:=k;
  30. end;
  31. for i:=1 to n do panduan[i]:=true;
  32. panduan[q]:=false;
  33. for i:=1 to n do begin
  34. if s[q,i]<>0 then a[1,i]:=s[q,i]
  35. else a[1,i]:=99999999;
  36. end;
  37. for i:=2 to n do begin
  38. min:=99999999;
  39. for j:=1 to n do begin
  40. if (panduan[j]=true)and(a[i-1,j]<min) then begin
  41. min:=a[i-1,j];
  42. p:=j;
  43. end;
  44. end;
  45. for j:=1 to n do begin
  46. a[i,j]:=a[i-1,j];
  47. if s[p,j]<>0 then
  48. if s[p,j]+a[i-1,p]<a[i-1,j] then
  49. a[i,j]:=s[p,j]+a[i-1,p];
  50. end;
  51. panduan[p]:=false;
  52. end;
  53. writeln(a[n,z]);
  54. close(input);
  55. close(output);
  56. End.