-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem3.py
46 lines (40 loc) · 1.35 KB
/
problem3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
infile = open('u1.in','r')
lines = infile.readlines()
num_test_cases = int(lines[0].strip())
class Junction:
def __init__(self, number, connections):
self.number = number #Junction ID #
self.connections = connections #list of Junction's it's connected to
def number_connections(self):
return len(self.connections)
def add_connection(self, junction):
self.connections.append(junction)
def is_reachable(self, junction):
return junction in self.connections #GOTTA CHANGE THIS
def assemble_network(n,network):
#assemble network based on sum line
assembled = n*[None]
for i in network:
s = sum(network[i].strip())
assembled[s] = network[i]
return assembled
#n is the number of junctions
#network is
#function outputs m (num of roads) and a list of m items, length 2 (roads from junction a->b)
def junction_solve(n, network):
junction_list = n*[Junction]
ordered = assemble_network(n, network)
#for each line in the path:
for a in range(len(ordered)):
for b in range(a,len(a)):
if ordered[a][b] and not b == a:
if not ordered[a].is_reachable(ordered[b]):
ordered[a].add_connection(ordered[b])
m = 0
path_list = []
for junction in junction_list:
m+=junction.number_connections()
for i in junction.connections:
path_list.append(junction.number, junction.connections[i].number)
return m, path_list
for i in range(num_test_cases):