Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Project2;
- {$APPTYPE CONSOLE}
- uses
- SysUtils;
- const
- N = 7;
- var
- i, rt, count: integer;
- Matrix: array[1..N, 1..N] of longint;
- visited: array[1..N] of boolean;
- tree: boolean = true;
- procedure DFS(rt: integer; prev: integer);
- var
- r: integer;
- begin
- count := count +1;
- if count <= N then
- begin
- visited[rt] := true;
- for r:= 1 to N do
- if (Matrix[rt, r] <> 0) and (r <> prev) then//(not visited[r]) then
- DFS(r, rt);
- end;
- end;
- begin
- Matrix[1][1]:=0;
- Matrix[1][2]:=1;
- Matrix[1][3]:=1;
- Matrix[1][4]:=0;
- Matrix[1][5]:=0;
- Matrix[1][6]:=0;
- Matrix[1][7]:=0;
- Matrix[2][1]:=1;
- Matrix[2][2]:=0;
- Matrix[2][3]:=0;
- Matrix[2][4]:=1;
- Matrix[2][5]:=1;
- Matrix[2][6]:=0;
- Matrix[2][7]:=0;
- Matrix[3][1]:=1;
- Matrix[3][2]:=0;
- Matrix[3][3]:=0;
- Matrix[3][4]:=0;
- Matrix[3][5]:=0;
- Matrix[3][6]:=1;
- Matrix[3][7]:=1;
- Matrix[4][1]:=0;
- Matrix[4][2]:=1;
- Matrix[4][3]:=0;
- Matrix[4][4]:=0;
- Matrix[4][5]:=0;
- Matrix[4][6]:=0;
- Matrix[4][7]:=0;
- Matrix[5][1]:=0;
- Matrix[5][2]:=1;
- Matrix[5][3]:=0;
- Matrix[5][4]:=0;
- Matrix[5][5]:=0;
- Matrix[5][6]:=1;
- Matrix[5][7]:=0;
- Matrix[6][1]:=0;
- Matrix[6][2]:=0;
- Matrix[6][3]:=1;
- Matrix[6][4]:=0;
- Matrix[6][5]:=1;
- Matrix[6][6]:=0;
- Matrix[6][7]:=0;
- Matrix[7][1]:=0;
- Matrix[7][2]:=0;
- Matrix[7][3]:=1;
- Matrix[7][4]:=0;
- Matrix[7][5]:=0;
- Matrix[7][6]:=0;
- Matrix[7][7]:=0;
- for i:= 1 to N do
- visited[i] := false;
- DFS(1,0);
- for i:= 1 to N do
- if visited[i] = false then
- tree := false;
- writeln(tree);
- readln;
- { TODO -oUser -cConsole Main : Insert code here }
- end.
Advertisement
Add Comment
Please, Sign In to add comment