Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. Uses crt;
  2. type
  3. masType = array[1..15,1..15] of integer;
  4. masT = array[1..1000] of boolean;
  5. var
  6. i,j,n, x, cnt,start,finish:integer;
  7. visited:masT;
  8. a:masType=
  9. (
  10. (0,1,0,1,1,0,0,0,0,0,0,0,0,0,0),
  11. (0,0,1,1,0,0,0,0,0,0,0,0,0,0,0),
  12. (0,0,0,0,0,0,1,0,1,0,0,0,0,0,0),
  13. (0,0,1,0,0,1,1,0,0,0,0,0,0,0,0),
  14. (0,0,0,1,0,0,0,1,0,0,0,0,0,0,0),
  15. (0,0,0,0,0,0,1,1,0,0,0,0,0,0,0),
  16. (0,0,0,0,0,0,0,1,1,1,1,0,0,0,0),
  17. (0,0,0,0,0,0,0,0,0,0,1,0,0,0,0),
  18. (0,0,0,0,0,0,0,0,0,1,0,1,0,1,0),
  19. (0,0,0,0,0,0,0,0,0,0,1,0,0,1,0),
  20. (0,0,0,0,0,0,0,0,0,0,0,0,0,1,0),
  21. (0,0,0,0,0,0,0,0,0,0,0,0,1,0,1),
  22. (0,0,0,0,0,0,0,0,0,0,0,0,0,0,1),
  23. (0,0,0,0,0,0,0,0,0,0,0,1,1,0,0),
  24. (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0));
  25. procedure dfs(var a:masType; var visited: masT; n, v, x: integer; var cnt: integer);
  26. var i: integer;
  27. begin
  28. if v = x then
  29. begin
  30. Inc(cnt);
  31. exit;
  32. end;
  33. if(v = 10) then visited[v] := true;
  34. for i := 1 to n do
  35. begin
  36. if (a[v, i]=1) and not visited[i] then
  37. begin
  38. dfs(a, visited, n, i, x, cnt);
  39. end;
  40. end;
  41. visited[v] := false;
  42. end;
  43. begin
  44. writeln('Матрица смежности:');
  45. n:=15;
  46. for i:=1 to n do
  47. begin
  48. for j:=1 to n do write(a[i,j]:2);
  49. writeln;
  50. end;
  51. start := 1;
  52. finish := 15;
  53. dfs(a, visited, n, start, finish, cnt);
  54. writeln('Путей из точки ',start,' в ',finish,' = ',cnt);
  55. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement