結果
| 問題 |
No.1983 [Cherry 4th Tune C] 南の島のマーメイド
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-08-28 13:34:14 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,579 bytes |
| コンパイル時間 | 669 ms |
| コンパイル使用メモリ | 82,560 KB |
| 実行使用メモリ | 305,792 KB |
| 最終ジャッジ日時 | 2024-10-15 12:23:08 |
| 合計ジャッジ時間 | 27,067 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 WA * 27 |
ソースコード
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
INF = float("INF")
MOD = 10 ** 9 + 7
MOD2 = 998244353
from heapq import heappop, heappush
import math
from collections import Counter, deque
from itertools import accumulate, combinations, combinations_with_replacement, permutations
from bisect import bisect_left, bisect_right
import decimal
n, m, q = map(int, input().split())
edge = [[] for _ in range(n)]
for i in range(m):
u, v = map(int, input().split())
u, v = u - 1, v - 1
edge[u].append(v)
edge[v].append(u)
ord = [-1] * n
low = [-1] * n
cnt = 0
def dfs(i, p):
global cnt
ord[i] = cnt
cnt += 1
low[i] = ord[i]
for to in edge[i]:
if to == p:
continue
if ord[to] != -1:
low[i] = min(low[i], ord[to])
continue
dfs(to, i)
low[i] = min(low[i], low[to])
dfs(0, -1)
def is_bridge(i, j):
if ord[i] < low[j]:
return True
return False
edge2 = [[] for _ in range(n)]
for i in range(n):
for j in edge[i]:
if is_bridge(i, j):
edge2[i].append(j)
seen = [-1] * n
for i in range(n):
if seen[i] != -1:
continue
seen[i] = i
que = deque()
que.append(i)
while que:
x = que.popleft()
for to in edge2[x]:
if seen[to] != -1:
continue
seen[to] = seen[x]
que.append(to)
for i in range(q):
x, y = map(int, input().split())
x, y = x - 1, y - 1
if seen[x] != seen[y]:
print("No")
else:
print("Yes")