Darkrai1337

Untitled

Feb 26th, 2022 (edited)
1,516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.59 KB | None | 0 0
  1. program Project2;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   SysUtils;
  7. const
  8.   N = 7;
  9. var
  10.   i, rt, count: integer;
  11.   Matrix: array[1..N, 1..N] of longint;
  12.   visited: array[1..N] of boolean;
  13.   tree: boolean = true;
  14.  
  15. procedure DFS(rt: integer; prev: integer);
  16. var
  17.   r: integer;
  18. begin
  19.   count := count +1;
  20.  if count <= N  then
  21.   begin
  22.     visited[rt] := true;
  23.   for r:= 1 to N do
  24.   if (Matrix[rt, r] <> 0) and (r <> prev) then//(not visited[r]) then
  25.     DFS(r, rt);
  26.   end;
  27. end;
  28.  
  29. begin
  30. Matrix[1][1]:=0;
  31. Matrix[1][2]:=1;
  32. Matrix[1][3]:=1;
  33. Matrix[1][4]:=0;
  34. Matrix[1][5]:=0;
  35. Matrix[1][6]:=0;
  36. Matrix[1][7]:=0;
  37.  
  38. Matrix[2][1]:=1;
  39. Matrix[2][2]:=0;
  40. Matrix[2][3]:=0;
  41. Matrix[2][4]:=1;
  42. Matrix[2][5]:=1;
  43. Matrix[2][6]:=0;
  44. Matrix[2][7]:=0;
  45.  
  46. Matrix[3][1]:=1;
  47. Matrix[3][2]:=0;
  48. Matrix[3][3]:=0;
  49. Matrix[3][4]:=0;
  50. Matrix[3][5]:=0;
  51. Matrix[3][6]:=1;
  52. Matrix[3][7]:=1;
  53.  
  54. Matrix[4][1]:=0;
  55. Matrix[4][2]:=1;
  56. Matrix[4][3]:=0;
  57. Matrix[4][4]:=0;
  58. Matrix[4][5]:=0;
  59. Matrix[4][6]:=0;
  60. Matrix[4][7]:=0;
  61.  
  62. Matrix[5][1]:=0;
  63. Matrix[5][2]:=1;
  64. Matrix[5][3]:=0;
  65. Matrix[5][4]:=0;
  66. Matrix[5][5]:=0;
  67. Matrix[5][6]:=1;
  68. Matrix[5][7]:=0;
  69.  
  70. Matrix[6][1]:=0;
  71. Matrix[6][2]:=0;
  72. Matrix[6][3]:=1;
  73. Matrix[6][4]:=0;
  74. Matrix[6][5]:=1;
  75. Matrix[6][6]:=0;
  76. Matrix[6][7]:=0;
  77.  
  78. Matrix[7][1]:=0;
  79. Matrix[7][2]:=0;
  80. Matrix[7][3]:=1;
  81. Matrix[7][4]:=0;
  82. Matrix[7][5]:=0;
  83. Matrix[7][6]:=0;
  84. Matrix[7][7]:=0;
  85.  
  86.   for i:= 1 to N do
  87.     visited[i] := false;
  88.   DFS(1,0);
  89.  
  90.  
  91.   for i:= 1 to N do
  92.     if visited[i] = false then
  93.         tree := false;
  94.  
  95.     writeln(tree);
  96.  
  97.   readln;
  98.   { TODO -oUser -cConsole Main : Insert code here }
  99. end.
  100.  
Advertisement
Add Comment
Please, Sign In to add comment