Skip to content

Commit

Permalink
외판원 순회 2
Browse files Browse the repository at this point in the history
  • Loading branch information
mu-hun committed Sep 6, 2024
1 parent ae2cf0a commit 7657696
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions acmicpc.net/problem/10971.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from itertools import permutations
from math import inf


def main(graph: tuple[tuple[int]]):
minimum = inf
length = len(graph)

for permutation in permutations(range(length)):
permutation += (permutation[0],)
total_weight = 0

for index in range(length):
weight = graph[permutation[index]][permutation[index + 1]]
if weight == 0:
total_weight = inf
break
total_weight += weight

minimum = min(minimum, total_weight)

return minimum


def test():
assert main(((0, 10, 15, 20), (5, 0, 9, 10), (6, 13, 0, 12), (8, 8, 9, 0))) == 35


if __name__ == "__main__":
print(main(tuple(tuple(map(int, input().split())) for __ in range(int(input())))))

0 comments on commit 7657696

Please sign in to comment.