23 lines
436 B
Python
23 lines
436 B
Python
|
import sys
|
||
|
from itertools import permutations as perm
|
||
|
|
||
|
C = set() # cities
|
||
|
D = dict() # distances
|
||
|
|
||
|
for line in sys.stdin.readlines():
|
||
|
c1, _, c2, _, d = line[:-1].split()
|
||
|
d = int(d)
|
||
|
D[(c1, c2)] = d
|
||
|
D[(c2, c1)] = d
|
||
|
C.add(c1)
|
||
|
C.add(c2)
|
||
|
|
||
|
S = 999999
|
||
|
L = 0
|
||
|
for r in perm(C): # brut force all possible routes
|
||
|
l = sum(D[(c1, c2)]
|
||
|
for c1, c2 in zip(r, r[1:]))
|
||
|
S = min(l, S)
|
||
|
L = max(l, L)
|
||
|
print(S, L)
|