21 lines
618 B
Python
21 lines
618 B
Python
def dimacs_convert_graph(filename):
|
|
with open(filename, 'r') as f:
|
|
for line in f:
|
|
line = line.strip()
|
|
|
|
if line.startswith('c'):
|
|
continue
|
|
|
|
elif line.startswith('p'):
|
|
_, _, n, e = line.split()
|
|
nodes = int(n)
|
|
edges = int(e)
|
|
adj = [[] for _ in range(nodes + 1)]
|
|
|
|
elif line.startswith('a'):
|
|
_, u, v, w = line.split()
|
|
u, v, w = int(u) - 1, int(v) - 1, int(w)
|
|
|
|
adj[u].append((v, w))
|
|
|
|
return nodes, adj |