Escolar Documentos
Profissional Documentos
Cultura Documentos
#Iniciar Grafo
def gerar_grafo(arestas):
grafo = defaultdict(list)
if v2 not in grafo[v1]:
grafo[v1].append(v2)
return grafo
#Obter Vértices
def get_vertices(grafo):
return list(grafo.keys())
#Obter Arestas
def get_arestas(grafo):
return [(c, v)
for c in grafo.keys()
for v in grafo[c]]
if v2 not in grafo[v1]:
grafo[v1].append(v2)
return grafo
arestas = [('A', 'B'), ('A', 'D'), ('B', 'C'), ('B', 'D'), ('B', 'E'), ('C', 'E'), ('D', 'E')]
grafo = gerar_grafo(arestas);
print(grafo)
print(get_vertices(grafo))
print(get_arestas(grafo))
print("Existe aresta")
else: