Home
О нас
Products
Services
Регистрация
Войти
Поиск
janekxzy
@janekxzy
July 2023
1
8
Report
100 Баллов! Задача комиваяжера на 10 городов и сделать алгоритм который выводит все гамильтоновы циклы в графе. python
Please enter comments
Please enter your name.
Please enter the correct email address.
Agree to
terms of service
You must agree before submitting.
Send
Answers & Comments
didkjdehh
def hamiltonian_cycles(graph, visited, path, start, length):
if length == len(graph) and start in graph[path[-1]]:
print(path + [start])
return
for v in graph:
if v in visited or v not in graph[path[-1]]:
continue
hamiltonian_cycles(graph, visited + [v], path + [v], start, length+1)
graph = {
1: [2, 3, 4],
2: [1, 3, 4],
3: [1, 2, 4],
4: [1, 2, 3, 5],
5: [4, 6, 7],
6: [5, 7, 8],
7: [5, 6, 8],
8: [6, 7, 9, 10],
9: [8, 10],
10: [8, 9]
}
Проверь у себя, сейчас не дома на телефоне писал
0 votes
Thanks 0
didkjdehh
Если что напиши перепишу
janekxzy
line 3
if length == len(graph) and start in graph[path[-1]]:
^
IndentationError: expected an indented block after function definition on line 1
More Questions From This User
See All
janekxzy
July 2023 | 0 Ответы
100 64a0414e1ae7e
Answer
janekxzy
July 2023 | 0 Ответы
100 100 python
Answer
×
Report "100 Баллов! Задача комиваяжера на 10 городов и сделать алгоритм который выводит все гамильтоновы циклы в графе. python"
Your name
Email
Reason
-Select Reason-
Pornographic
Defamatory
Illegal/Unlawful
Spam
Other Terms Of Service Violation
File a copyright complaint
Description
Helpful Links
О нас
Политика конфиденциальности
Правила и условия
Copyright
Контакты
Helpful Social
Get monthly updates
Submit
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
def hamiltonian_cycles(graph, visited, path, start, length):
if length == len(graph) and start in graph[path[-1]]:
print(path + [start])
return
for v in graph:
if v in visited or v not in graph[path[-1]]:
continue
hamiltonian_cycles(graph, visited + [v], path + [v], start, length+1)
graph = {
1: [2, 3, 4],
2: [1, 3, 4],
3: [1, 2, 4],
4: [1, 2, 3, 5],
5: [4, 6, 7],
6: [5, 7, 8],
7: [5, 6, 8],
8: [6, 7, 9, 10],
9: [8, 10],
10: [8, 9]
}
Проверь у себя, сейчас не дома на телефоне писал
if length == len(graph) and start in graph[path[-1]]:
^
IndentationError: expected an indented block after function definition on line 1