csci5451/assignments/03/dataset/gen.py

17 lines
556 B
Python
Raw Normal View History

2023-11-25 02:05:20 +00:00
import sys
with open(sys.argv[1]) as f:
num_nodes, num_edges = map(int, f.readline().strip().split(" "))
all_edges = set()
for _ in range(num_edges):
from_edge, to_edge = map(int, f.readline().strip().split(" "))
all_edges.add((from_edge, to_edge))
all_edges.add((to_edge, from_edge))
all_edges = sorted(list(all_edges))
new_num_edges = len(all_edges)
with open(sys.argv[2], "w") as f:
f.write(f"{num_nodes} {new_num_edges}\n")
for from_edge, to_edge in all_edges:
f.write(f"{from_edge} {to_edge}\n")