Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const maxN = 105;
- maxC = 1000000007;
- var a, c: array[1..maxN, 1..maxN] of longint;
- n, s, t, low, high, mid, ans, u, v, w: longint;
- trace, tr_ans: array[1..maxN] of longint;
- procedure dfs(u: longint);
- var v: longint;
- begin
- for v:=1 to n do
- if (trace[v] = 0) and (a[u,v] = 1) then
- begin
- trace[v]:=u;
- dfs(v);
- end;
- end;
- begin
- assign(input, 'taitrong.inp'); reset(input);
- assign(output,'taitrong.out'); rewrite(output);
- read(n, s, t);
- fillchar(c, sizeof(c), 0);
- low:= maxC;
- high:=0;
- while not eof do
- begin
- read(u, v, w);
- if w < low then low:=w;
- if w > high then high:=w;
- c[u,v]:=w;
- c[v,u]:=w;
- end;
- while low <= high do
- begin
- mid:=(low + high) div 2;
- for u:=1 to n do
- for v:=1 to n do
- if c[u,v] >= mid then a[u,v]:=1
- else a[u,v]:=0;
- for u:=1 to n do trace[u]:=0;
- trace[t]:=t;
- dfs(t);
- if trace[s] <> 0 then
- begin
- ans:=mid;
- tr_ans:=trace;
- low:= mid+1;
- end
- else high:=mid-1;
- end;
- writeln(ans);
- write(s);
- while s <> t do
- begin
- write(' ', tr_ans[s]);
- s:=tr_ans[s];
- end;
- close(input); close(output);
- end.
Advertisement
Add Comment
Please, Sign In to add comment