Skip to content

Instantly share code, notes, and snippets.

@jordi-petit
Created May 10, 2018 18:17
Show Gist options
  • Save jordi-petit/158007530284c298a568de9a74e716cf to your computer and use it in GitHub Desktop.
Save jordi-petit/158007530284c298a568de9a74e716cf to your computer and use it in GitHub Desktop.
AP2 2018-05-10
from jutge import read
def dfs(G, u, y, vis):
if not vis[u]:
vis[u] = True
for v in G[u]:
if vis[y]:
return
dfs(G, v, y, vis)
def main():
n, m = read(int, int)
G = [[] for i in range(n)]
for i in range(m):
u, v = read(int, int)
G[u].append(v)
x, y = read(int, int)
vis = [False for i in range(n)]
dfs(G, x, y, vis)
print("yes" if vis[y] else "no")
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment