forked from shunr/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathccc13s4.py
More file actions
38 lines (34 loc) · 725 Bytes
/
ccc13s4.py
File metadata and controls
38 lines (34 loc) · 725 Bytes
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
import sys
from heapq import *
inf = sys.maxsize
def input():
return sys.stdin.readline()
n, m = [int(i) for i in input().split()]
graph = {}
for i in range(m):
a, b = [int(_) for _ in input().split()]
if a not in graph.keys():
graph[a] = []
graph[a].append(b)
a, b = [int(_) for _ in input().split()]
def taller(G, a, b):
q = [a]
visited = set()
while q:
x = q.pop()
if x not in G.keys():
continue
if b in G[x]:
return True
break
for g in G[x]:
if g not in visited:
q.append(g)
visited.add(x)
return False
if taller(graph, a, b):
print("yes")
elif taller(graph, b, a):
print("no")
else:
print("unknown")