-
Notifications
You must be signed in to change notification settings - Fork 1
/
stub.py
executable file
·46 lines (37 loc) · 1.24 KB
/
stub.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
46
#!/usr/bin/python3
r"""
The boring parts of a solution to this problem.
"""
def main():
# Read vertices from stdin
num_vertices = int(input())
vertices = list(range(num_vertices))
# Read edges from stdin
num_edges = int(input())
edges = [int_pair(input()) for _ in range(num_edges)]
# Construct the graph
graph = Graph(vertices, edges)
# Read queries from stdin
num_queries = int(input())
queries = [int_pair(input()) for _ in range(num_queries)]
# Answer the queries on stdout
for vertex1, vertex2 in queries:
print('yes' if graph.has_path_between(vertex1, vertex2) else 'no')
def int_pair(string):
pair = tuple(map(int, string.split()))
if len(pair) != 2: raise ValueError('wrong number of items')
return pair
class Graph:
def __init__(self, vertices, edges):
self.vertices = vertices
self.edges = edges
neighbours = {v: set() for v in vertices}
for v1, v2 in edges:
neighbours[v1].add(v2)
neighbours[v2].add(v1)
self.neighbours = neighbours
def has_path_between(self, vertex1, vertex2):
#TODO replace this with your implementation
raise NotImplementedError
if __name__ == '__main__':
main()