結果

問題 No.1983 [Cherry 4th Tune C] 南の島のマーメイド
ユーザー neginagineginagi
提出日時 2022-08-28 13:44:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,598 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 91,648 KB
最終ジャッジ日時 2024-04-23 12:37:23
合計ジャッジ時間 45,260 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
11,648 KB
testcase_01 AC 35 ms
11,520 KB
testcase_02 AC 35 ms
11,520 KB
testcase_03 AC 34 ms
11,520 KB
testcase_04 AC 35 ms
11,520 KB
testcase_05 AC 34 ms
11,648 KB
testcase_06 AC 35 ms
11,520 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 34 ms
11,648 KB
testcase_34 AC 929 ms
50,816 KB
testcase_35 AC 1,563 ms
91,648 KB
testcase_36 AC 1,337 ms
69,504 KB
testcase_37 AC 35 ms
11,648 KB
testcase_38 AC 392 ms
11,648 KB
testcase_39 AC 1,547 ms
91,648 KB
testcase_40 AC 1,472 ms
80,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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] or ord[j] < low[i]:
        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")
0