initial commit
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
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
|
||||
Reference in New Issue
Block a user