Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def skip():
- print("_" * 60)
- print("_" * 60)
- skip()
- # Друге завдання
- graph = [[1, 3], [0, 3, 4, 5], [4, 5], [0, 1, 5], [1, 2], [1, 2, 3]]
- pozhat = [-1]*len(graph)
- print ('Початковий стан', pozhat)
- def func(s):
- global pozhat
- pozhat[s] = 0
- zherg = [s]
- print('Стан перегляду вершин')
- while zherg:
- print(pozhat)
- v = zherg.pop(0)
- print('відвідали вершину', v)
- for m in graph[v]:
- if pozhat[m] == -1:
- zherg.append(m)
- pozhat[m]=pozhat[v] + 1
- for i in range(2, len(graph)):
- if pozhat[i] == -1:
- func(i)
- skip()
- # Четверте завдання
- graph = [[4, 5], [5], [3, 4], [2, 4], [0, 2, 3], [0, 1]]
- stan=[False for i in range(len(graph))]
- print(stan)
- print('Порядок обходу вершин')
- def func(v):
- print(v, end=" ")
- stan[v]= True
- for vartex in graph[v]:
- if not stan[vartex]:
- func(vartex)
- for c in range(3, len(graph)):
- if not stan[c]:
- func(c)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement