-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph.py
More file actions
executable file
·30 lines (29 loc) · 925 Bytes
/
Copy pathGraph.py
File metadata and controls
executable file
·30 lines (29 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#Adjacency Matrix Reprsentation
def graphM():
n = int(input('Value of Max. Node: '))
e = int(input('Edge: '))
matrix = [0] * (n+1)
for i in range(n+1):
matrix[i] = [0] * (n+1)
typ = input('Type Of Graph: ')
chk = input('Weighted Or Non Weighted: ')
if chk =='W' and typ =='D':
for i in range(e):
n1,n2,v = map(int,input().split())
matrix[n1][n2] =v
elif chk =='W' and typ =='U':
for i in range(e):
n1,n2,v = map(int,input().split())
matrix[n1][n2] =v
matrix[n2][n1] =v
elif chk =='NW' and typ =='U':
for i in range(e):
n1,n2 = map(int,input().split())
matrix[n1][n2] =1
matrix[n2][n1] =1
elif chk =='NW' and typ =='D':
for i in range(e):
n1,n2 = map(int,input().split())
matrix[n1][n2] =1
return print(matrix)
graphM()