code: def kruskal(graph, weight):
      
      uf = UnionFind(len(graph))
      edges = []
      for u in range(len(graph)):
          for v in graph[u]:
              edges.append((weight[u][v], u, v))
      edges.sort()
      mst = []
      for w, u, v in edges:
          if uf.union(u, v):
              mst.append((u, v))
      return mst
docs: Minimum spanning tree by Kruskal
  
      :param graph: undirected graph in listlist or listdict format
      :param weight: in matrix format or same listdict graph
      :returns: list of edges of the tree
      :complexity: ``O(|E|log|E|)``