Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uses
- SysUtils, Math;
- var
- n, i, j, tt : longint;
- a : array[0..5010, 0..5010] of boolean;
- g : array[0..5010] of array of longint;
- ch : char;
- w : array[0..5010] of boolean;
- procedure ok(a, b, c : longint);
- begin
- write(a, ' ', b, ' ', c);
- halt(0);
- end;
- procedure dfs(v, c, f : longint);
- var
- i, tt, tto : longint;
- begin
- w[v] := true;
- tt := length(g[v]) - 1;
- for i := 0 to tt do begin
- tto := g[v][i];
- if c = 1 then begin
- if not w[tto] then dfs(tto, 2, v);
- end else
- if c = 2 then begin
- if a[tto][f] then ok(f, v, tto) else
- if not w[tto] then dfs(tto, 2, v);
- end;
- end;
- end;
- begin
- readln(n);
- for i := 1 to n do begin
- for j := 1 to n do begin
- read(ch);
- a[i][j] := ch = '1';
- end;
- readln;
- end;
- for i := 1 to n do
- for j := 1 to n do
- if a[i][j] then begin
- tt := length(g[i]);
- setlength(g[i], tt + 1);
- g[i][tt] := j;
- end;
- fillchar(w, sizeof(w), 0);
- for i := 1 to n do
- if not w[i] then dfs(i, 1, i);
- write(-1);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement