giabinh

TaiTrongPascal

Jul 22nd, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.25 KB | None | 0 0
  1. const fi='trongtai.inp';
  2.       fo='trongtai.out';
  3.  
  4. var a: array [1..25, 1..25] of longint;
  5.     b, trace, ways: array [1..25] of longint;
  6.     n, s, t, u, v, w, ans, m, tmp, line, i: longint;
  7.     done: array [1..10000] of boolean;
  8.  
  9. procedure DFS(u, w: longint);
  10. var v: longint;
  11. begin
  12.   for v:=1 to n do
  13.     if (trace[v]=0) and (a[u, v]>0) and (a[u,v]>=w) then
  14.       begin
  15.         trace[v]:=u;
  16.         DFS(v, w)
  17.       end;
  18. end;
  19.  
  20. procedure thu(w: longint);
  21. begin
  22.   fillchar(trace, sizeof(trace), 0);
  23.   trace[s]:=-1; DFS(s, w);
  24.  
  25.   if (trace[t]<>0) and (w>ans) then
  26.     begin
  27.       ans:=w;
  28.  
  29.       tmp:=t; m:=1;
  30.       while tmp<>s do
  31.         begin
  32.           ways[m]:=tmp; tmp:=trace[tmp]; inc(m);
  33.         end;
  34.       ways[m]:=s;
  35.     end;
  36.  
  37.   done[b[i]]:=true;
  38. end;
  39.  
  40. begin
  41.   assign(input, fi); reset(input);
  42.   assign(output, fo); rewrite(output);
  43.  
  44.   readln(n, s, t);
  45.   fillchar(a, sizeof(a), 0); line:=0; ans:=-1;
  46.   while not(eof) do
  47.     begin
  48.       readln(u, v, w);
  49.       a[u, v]:=w; a[v, u]:=w;
  50.       inc(line); b[line]:=w;
  51.     end;
  52.  
  53.   fillchar(done, sizeof(done), false);
  54.   for i:=1 to line do
  55.     if not done[b[i]] then thu(b[i]);
  56.  
  57.   writeln(ans);
  58.   for i:=m downto 1 do write(ways[i],' ');
  59.  
  60.   close(input); close(output);
  61. end.
Advertisement
Add Comment
Please, Sign In to add comment