In [ ]:
n = int(input("number of nodes: "))
m = int(input("number of edges: "))
In [ ]:
E={}
V={ i:[] for i in list(range(n))}
#V[1].append(1)
for i in range(m):
E[i]=list(map(int, input("E["+str(i)+"]: ").split()))
V[int(E[i][0])].append(int(E[i][1]))
In [3]:
print("Edges list: " + str(E))
print("Adjacency list: "+ str(V))
In [10]:
print("Adjacency matrix: ")
fs = lambda i,j: int(j in V[i])
for i in range(n):
print(list(fs(i,j) for j in range (n)))
In [37]:
fi = lambda i,j: int(j in E[i])
print("Adjacency matrix: ")
for j in range(m):
print(list(fi(i,j) for i in range (n)))
In [ ]: