Created
November 6, 2012 00:44
-
-
Save gsnedders/4021626 to your computer and use it in GitHub Desktop.
path verification for alg3 ae1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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