Skip to content

Instantly share code, notes, and snippets.

@pknowledge
Created July 4, 2020 19:41
Show Gist options
  • Save pknowledge/70792a63cba82fc4b47fa2b0cc42cb42 to your computer and use it in GitHub Desktop.
Save pknowledge/70792a63cba82fc4b47fa2b0cc42cb42 to your computer and use it in GitHub Desktop.
Competitive Programming with Python | Graph Representation | ADJACENCY LIST VS. ADJACENCY MATRIX https://youtu.be/CGOox3yLLYU
# UNDIRECTED GRAPH
'''
ADJ MATRIX
ADJ LIST
'''
'''
V E
FOR EVERY EDGE
U V
7 9
A B
A C
A F
C E
C F
C D
D E
D G
G F
'''
from collections import defaultdict
graph = defaultdict(list)
v,e = map(int,input().split())
for i in range(e):
u,v = map(str,input().split())
graph[u].append(v)
graph[v].append(u)
for v in graph:
print(v,graph[v])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment