import numpy as np import networkx as nx import argparse parser = argparse.ArgumentParser(description='') parser.add_argument('-g', '--graph', dest='graph', action='store', default=None) args = parser.parse_args() if not args.graph: print("need a graph as input") exit() def read_graph(graph_file): with open(graph_file) as f: n = int(f.readline()) m = int(f.readline()) A = [[0] * n for _ in range(n)] for _ in range(m): [u, v] = map(int, f.readline().split()) A[u][v] = 1 A[v][u] = 1 G = nx.Graph(np.array(A)) return G def max_comp_size(G): return max([len(c) for c in nx.connected_components(G)]) del_list = [] G = read_graph(args.graph) n = len(G.nodes) while max_comp_size(G) > n / 2: mnc = nx.minimum_node_cut(G=G) del_list.append(mnc) G.remove_nodes_from(mnc) for u in del_list: print(u)