Advertisement
hoanmalai

Tạo danh sách cạnh

May 25th, 2022
804
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Edge:
  2.     def __init__(self, u, v):
  3.         self.u = u
  4.         self.v = v
  5.     def __str__(self):
  6.         return '{0} {1}'.format(self.u, self.v)
  7.  
  8. n = int(input())
  9.  
  10. adj_matrix = []
  11. for i in range(n):
  12.     new_row = list(map(int, input().split()))
  13.     adj_matrix.append(new_row)
  14.  
  15. edge_list = []
  16. for u in range(n):
  17.     for v in range(u + 1, n):
  18.         if adj_matrix[u][v] == 1:
  19.             edge_list.append(Edge(u, v))
  20.  
  21. print(len(edge_list))
  22. for edge in edge_list:
  23.     print(edge)
Advertisement
RAW Paste Data Copied
Advertisement