Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- inf = float("inf")
- class Grafo:
- def __init__(self):
- # VĂ©rtices: list(pair(str, str, int))
- # Ex: [('S', 'A', 3), ..., ('H', 'G', 8)]
- vertices = []
- i = None
- while(i != ''):
- try:
- i = input()
- origem, destino, peso, = i.strip().split(' ')
- vertices.append((origem, destino, int(peso)))
- except:
- print(vertices)
- break
- # No: set(list(str,str))
- # Ex: {['S','A'], ..., ['H','G']}
- self.no = set()
- for v in vertices:
- self.no.update([v[0], v[1]])
- # Matriz: dict(str: set())
- # Ex: {'S': {'A', 3}}
- self.matriz = {par: set() for par in self.no}
- for v in vertices:
- self.matriz[v[0]].add((v[1], v[2]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement