Advertisement
Iam_Sandeep

Untitled

May 12th, 2022
614
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. def printSolution(numOfVertices, distance):
  3.     for i in range(numOfVertices):
  4.         for j in range(numOfVertices):
  5.               print(distance[i][j], end="  ")
  6.         print(" ")
  7.  
  8. def floydWarshall(numOfVertices, G):
  9.     distance = G
  10.     for k in range(numOfVertices):
  11.         for i in range(numOfVertices):
  12.             for j in range(numOfVertices):
  13.                 distance[i][j] = max(distance[i][j], distance[i][k]+distance[k][j])
  14.  
  15.    
  16.     print(max(max(i) for i in G))
  17.    
  18. v=int(input("Enter vertices"))
  19. G=[[float('-inf')]*v for i in range(v)]
  20.  
  21. e=int(input("Enter edge count"))
  22. print("enter u,v,w")
  23. for _ in range(e):
  24.     u,v,w=input().split()
  25.     u,v,w=int(u)-1,int(v)-1,float(w)
  26.     G[u][v]=w
  27.  
  28. for i in range(v):
  29.     G[i][i]=0
  30.  
  31. floydWarshall(v+2, G)
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement