Skip to content

Instantly share code, notes, and snippets.

@gsnedders
Created November 6, 2012 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsnedders/4021626 to your computer and use it in GitHub Desktop.
Save gsnedders/4021626 to your computer and use it in GitHub Desktop.
path verification for alg3 ae1
import sys
if len(sys.argv) > 1:
name = sys.argv[1]
else:
name = raw_input("Input file: ")
fp = open(name, "r")
count = int(fp.readline().strip())
vertices = []
for i in xrange(count):
line = fp.readline()
vertices.append(map(int, line.split()))
for to, weight in enumerate(vertices[-1]):
if to < i:
if vertices[to][i] != weight:
print "This file represents a directed graph"
sys.exit(0)
print "This file represents an undirected graph"
import sys
if len(sys.argv) > 1:
name = sys.argv[1]
else:
name = raw_input("Input file: ")
fp = open(name, "r")
count = int(fp.readline().strip())
vertices = []
for i in xrange(count):
line = fp.readline()
vertices.append(map(int, line.split()))
path_vertices = map(int, raw_input("Input space separated vertex list: ").split())
length = 0
for i in xrange(len(path_vertices) - 1):
f = path_vertices[i]
t = path_vertices[i + 1]
length += vertices[f][t]
print length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment