Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- N = np.array([[0,1,1,1,1,1,0,0],
- [0,0,1,0,1,0,0,0],
- [0,0,0,1,0,0,0,0],
- [0,0,0,0,1,0,0,0],
- [0,0,0,0,0,1,0,0],
- [0,0,1,0,0,0,1,1],
- [0,0,0,0,0,1,0,1],
- [0,0,0,0,0,1,1,0]])
- def algo (W):
- n=len(W)
- A = [[W[i][j] for j in range(n)] for i in range(n)]
- for k in range(n):
- for i in range(n):
- for j in range(n):
- A[i][j] = min(A[i][j], A[i][k] + A[k][j])
- return k
- def main():
- tree = None
- print('matrix1\n')
- print('matrix2\n')
- print('matrix3\n')
- print('matrix4\n')
- print('matrix5\n')
- print('To end the process enter:- quit \n ')
- while True:
- do = input('What would you like to do? ').split()
- operation = do[0].strip().lower()
- if operation == 'matrix1':
- print('Диаметр графа равен:', algo([
- [0,1,1,1,1,1,0,0],
- [0,0,1,0,1,0,0,0],
- [0,0,0,1,0,0,0,0],
- [0,0,0,0,1,0,0,0],
- [0,0,0,0,0,1,0,0],
- [0,0,1,0,0,0,1,1],
- [0,0,0,0,0,1,0,1],
- [0,0,0,0,0,1,1,0]]))
- elif operation == 'matrix2':
- print('Диаметр графа равен:', algo([
- [0,1,1,1,1,1],
- [0,0,1,0,1,0],
- [0,0,0,1,0,0],
- [0,0,0,0,1,0],
- [0,0,0,0,0,1],
- [0,0,1,0,0,0]]))
- elif operation == 'matrix3':
- print('Диаметр графа равен:', algo([
- [0,1,0,0,0],
- [0,0,1,1,0],
- [0,0,0,0,1],
- [0,0,0,0,1],
- [0,0,0,0,1]]))
- elif operation == 'matrix4':
- print('Диаметр графа равен:', algo([
- [0,1,1,1,1,1,0,0,1],
- [0,0,1,0,1,0,0,1,0],
- [0,0,0,1,0,0,1,0,0],
- [0,0,0,0,1,1,0,0,0],
- [0,0,0,0,1,1,0,0,0],
- [0,0,1,1,0,0,1,1,0],
- [0,0,1,0,0,1,0,1,0],
- [0,1,0,0,0,1,0,1,0],
- [1,0,0,0,0,1,1,0,0]]))
- elif operation == 'matrix5':
- print('Диаметр графа равен:', algo([
- [0,1,0,0],
- [0,0,1,1],
- [0,1,0,0],
- [0,0,1,0]]))
- elif operation == 'quit':
- break
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement