Skip to content

Instantly share code, notes, and snippets.

@maehrm
Last active April 22, 2024 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maehrm/6ba94ee86f6fee8963bad5f32b343286 to your computer and use it in GitHub Desktop.
Save maehrm/6ba94ee86f6fee8963bad5f32b343286 to your computer and use it in GitHub Desktop.
import sys
input = sys.stdin.readline
N, M, Q = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
x, y = map(lambda n: int(n) - 1, input().split())
G[y].append(x) # 子が親へのポインタを持つようなグラフ
ans = []
for i in range(N):
bs = 1 << i
for v in G[i]:
bs |= ans[v]
ans.append(bs)
for _ in range(Q):
a, b = map(lambda n: int(n) - 1, input().split())
if (ans[b] >> a) & 1:
print("Yes")
else:
print("No")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment