-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gregory Meno
committed
Jan 22, 2012
1 parent
a8cf05b
commit 3628378
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import sys | ||
|
||
graph = {} | ||
|
||
def build_graph(graph_file): | ||
with open(graph_file) as f: | ||
for l in f.readlines(): | ||
start, end = l.strip('\n').split(',') | ||
arc_list = graph.get(start, []) | ||
arc_list.append(end) | ||
if start not in graph: | ||
graph[start] = arc_list | ||
|
||
def arc_in(graph, start, end): | ||
return end in graph.get(start,[]) | ||
|
||
def edge_in(graph, first, second): | ||
return arc_in(graph, first, second) and arc_in(graph, second, first) | ||
|
||
if __name__ == '__main__': | ||
build_graph(sys.argv[1]) | ||
|
||
print graph | ||
print edge_in(graph, '1','3') | ||
print edge_in(graph, '1','8') | ||
print arc_in(graph, '1','8') |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
1,3 | ||
3,1 | ||
1,8 | ||
2,3 | ||
2,4 | ||
2,6 | ||
3,7 |