Created
July 4, 2020 19:41
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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