• API
• FAQ
• Tools
• Archive
daily pastebin goal
62%
SHARE
TWEET

# Untitled

a guest Jan 23rd, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. program DFS_1;
2.
3. var
4.   Arid : array of array[0..1000] of integer;
5.   used : array of boolean;
6.   F : boolean;
7.   i, n, m, a, b : integer;
8.
9. procedure DFS(p : integer; plast : integer = 0);
10. var i:integer;
11. begin
12.   used[p] := true;
13.   for i := 1 to Arid[p][0] do
14.     if (used[Arid[p][i]] = false) then
15.     begin
16.       plast := p;
17.       DFS(Arid[p][i], plast);
18.     end
19.     else
20.       if plast <> Arid[p][i] then
21.         F := false;
22. end;
23.
24. begin
26.   if (n <= m) or (n - 1 <> m) or (n < 0) or (m < 0) then
27.   begin
28.     writeln('False');
29.   end
30.   else
31.   begin
32.     //************************
33.     setlength(Arid, n);
34.     setlength(used, n);
35.     F := true;
36.     //инициализация
37.     for i := 0 to n-1 do
38.     begin
39.       Arid[i][0] := 0;
40.       used[i] := false;
41.     end;
42.
43.     for i := 0 to m-1 do
44.     begin
46.       Arid[a-1][0] += 1;
47.       Arid[a-1][Arid[a-1][0]] := b - 1;
48.       Arid[b-1][0] += 1;
49.       Arid[b-1][Arid[b-1][0]] := a - 1;
50.     end;
51.
52.     DFS(0);
53.
54.     for i := 0 to n-1 do
55.       if (used[i] = false) then F := false;
56.
57.
58.     if F then
59.       writeln('True')
60.     else
61.       writeln('False');
62.   end;