Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fi='trongtai.inp';
- fo='trongtai.out';
- var a: array [1..25, 1..25] of longint;
- b, trace, ways: array [1..25] of longint;
- n, s, t, u, v, w, ans, m, tmp, line, i: longint;
- done: array [1..10000] of boolean;
- procedure DFS(u, w: longint);
- var v: longint;
- begin
- for v:=1 to n do
- if (trace[v]=0) and (a[u, v]>0) and (a[u,v]>=w) then
- begin
- trace[v]:=u;
- DFS(v, w)
- end;
- end;
- procedure thu(w: longint);
- begin
- fillchar(trace, sizeof(trace), 0);
- trace[s]:=-1; DFS(s, w);
- if (trace[t]<>0) and (w>ans) then
- begin
- ans:=w;
- tmp:=t; m:=1;
- while tmp<>s do
- begin
- ways[m]:=tmp; tmp:=trace[tmp]; inc(m);
- end;
- ways[m]:=s;
- end;
- done[b[i]]:=true;
- end;
- begin
- assign(input, fi); reset(input);
- assign(output, fo); rewrite(output);
- readln(n, s, t);
- fillchar(a, sizeof(a), 0); line:=0; ans:=-1;
- while not(eof) do
- begin
- readln(u, v, w);
- a[u, v]:=w; a[v, u]:=w;
- inc(line); b[line]:=w;
- end;
- fillchar(done, sizeof(done), false);
- for i:=1 to line do
- if not done[b[i]] then thu(b[i]);
- writeln(ans);
- for i:=m downto 1 do write(ways[i],' ');
- close(input); close(output);
- end.
Advertisement
Add Comment
Please, Sign In to add comment