Skip to content

Commit 59e1105

Browse files
authored
part 1- graph theory
1 parent 892cb1d commit 59e1105

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

unweighted-graph.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# part 1- graph theory
2+
# make a dictionary of all the nodes(vertices) in the unordered graph
3+
from collections import defaultdict
4+
5+
graph = defaultdict(list)
6+
v,e = map(int,input().split())
7+
# v -> no. of vertices
8+
# e -> no. of edges
9+
for i in range(e):
10+
u, v = input().split()
11+
graph[u].append(v)
12+
graph[v].append(u)
13+
for i in graph:
14+
print(i,graph[i])

0 commit comments

Comments
 (0)