giabinh

TaiTrong_Pascal_10

Jul 24th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.38 KB | None | 0 0
  1. const maxN = 105;
  2.       maxC = 1000000007;
  3.  
  4. var a, c: array[1..maxN, 1..maxN] of longint;
  5.     n, s, t, low, high, mid, ans, u, v, w: longint;
  6.     trace, tr_ans: array[1..maxN] of longint;
  7.  
  8. procedure dfs(u: longint);
  9. var v: longint;
  10. begin
  11.   for v:=1 to n do
  12.     if (trace[v] = 0) and (a[u,v] = 1) then
  13.       begin
  14.         trace[v]:=u;
  15.         dfs(v);
  16.       end;
  17. end;
  18.  
  19. begin
  20.  
  21.     assign(input, 'taitrong.inp'); reset(input);
  22.     assign(output,'taitrong.out'); rewrite(output);
  23.  
  24.     read(n, s, t);
  25.     fillchar(c, sizeof(c), 0);
  26.     low:= maxC;
  27.     high:=0;
  28.     while not eof do
  29.       begin
  30.         read(u, v, w);
  31.         if w < low then low:=w;
  32.         if w > high then high:=w;
  33.         c[u,v]:=w;
  34.         c[v,u]:=w;
  35.       end;
  36.  
  37.     while low <= high do
  38.       begin
  39.         mid:=(low + high) div 2;
  40.  
  41.         for u:=1 to n do
  42.           for v:=1 to n do
  43.             if c[u,v] >= mid then a[u,v]:=1
  44.             else a[u,v]:=0;
  45.  
  46.         for u:=1 to n do trace[u]:=0;
  47.         trace[t]:=t;
  48.         dfs(t);
  49.         if trace[s] <> 0 then
  50.           begin
  51.             ans:=mid;
  52.             tr_ans:=trace;
  53.             low:= mid+1;
  54.           end
  55.         else high:=mid-1;
  56.       end;
  57.  
  58.     writeln(ans);
  59.     write(s);
  60.     while s <> t do
  61.       begin
  62.         write(' ', tr_ans[s]);
  63.         s:=tr_ans[s];
  64.       end;
  65.  
  66.     close(input); close(output);
  67. end.
Advertisement
Add Comment
Please, Sign In to add comment