Advertisement
VSS2

Exercicio SI 2020.2 UCS

Jun 17th, 2021
1,465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. inf = float("inf")
  2.  
  3. class Grafo:
  4.     def __init__(self):
  5.         # VĂ©rtices: list(pair(str, str, int))
  6.         # Ex: [('S', 'A', 3), ..., ('H', 'G', 8)]
  7.         vertices = []
  8.         i = None
  9.         while(i != ''):
  10.             try:
  11.                 i = input()
  12.                 origem, destino, peso, = i.strip().split(' ')
  13.                 vertices.append((origem, destino, int(peso)))
  14.             except:
  15.                 print(vertices)
  16.                 break
  17.            
  18.         # No: set(list(str,str))
  19.         # Ex: {['S','A'], ..., ['H','G']}
  20.         self.no = set()
  21.         for v in vertices:
  22.             self.no.update([v[0], v[1]])
  23.  
  24.         # Matriz: dict(str: set())
  25.         # Ex: {'S': {'A', 3}}
  26.         self.matriz = {par: set() for par in self.no}
  27.         for v in vertices:
  28.             self.matriz[v[0]].add((v[1], v[2]))
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement