Last active
April 22, 2024 05:01
-
-
Save maehrm/6ba94ee86f6fee8963bad5f32b343286 to your computer and use it in GitHub Desktop.
059 - Many Graph Queries(★7) https://atcoder.jp/contests/typical90/tasks/typical90_bg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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