結果

問題 No.1983 [Cherry 4th Tune C] 南の島のマーメイド
ユーザー neginagineginagi
提出日時 2022-08-28 13:55:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,811 ms / 4,000 ms
コード長 1,932 bytes
コンパイル時間 296 ms
コンパイル使用メモリ 13,056 KB
実行使用メモリ 103,040 KB
最終ジャッジ日時 2024-04-23 12:53:15
合計ジャッジ時間 40,327 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
11,520 KB
testcase_01 AC 32 ms
11,520 KB
testcase_02 AC 31 ms
11,520 KB
testcase_03 AC 33 ms
11,520 KB
testcase_04 AC 31 ms
11,520 KB
testcase_05 AC 30 ms
11,648 KB
testcase_06 AC 29 ms
11,648 KB
testcase_07 AC 36 ms
11,520 KB
testcase_08 AC 51 ms
12,416 KB
testcase_09 AC 70 ms
13,824 KB
testcase_10 AC 83 ms
14,716 KB
testcase_11 AC 86 ms
14,704 KB
testcase_12 AC 66 ms
13,056 KB
testcase_13 AC 897 ms
45,628 KB
testcase_14 AC 1,020 ms
47,888 KB
testcase_15 AC 1,311 ms
66,648 KB
testcase_16 AC 713 ms
49,092 KB
testcase_17 AC 1,033 ms
48,848 KB
testcase_18 AC 1,191 ms
67,360 KB
testcase_19 AC 1,484 ms
74,320 KB
testcase_20 AC 1,184 ms
63,360 KB
testcase_21 AC 1,142 ms
56,784 KB
testcase_22 AC 1,216 ms
59,136 KB
testcase_23 AC 1,773 ms
73,984 KB
testcase_24 AC 1,757 ms
73,820 KB
testcase_25 AC 1,773 ms
73,932 KB
testcase_26 AC 1,762 ms
73,984 KB
testcase_27 AC 1,745 ms
73,996 KB
testcase_28 AC 1,804 ms
73,972 KB
testcase_29 AC 1,748 ms
73,924 KB
testcase_30 AC 1,782 ms
73,844 KB
testcase_31 AC 1,811 ms
73,960 KB
testcase_32 AC 1,784 ms
74,000 KB
testcase_33 AC 31 ms
11,776 KB
testcase_34 AC 800 ms
47,672 KB
testcase_35 AC 1,252 ms
103,040 KB
testcase_36 AC 1,136 ms
66,496 KB
testcase_37 AC 32 ms
11,648 KB
testcase_38 AC 378 ms
11,904 KB
testcase_39 AC 1,596 ms
102,912 KB
testcase_40 AC 1,544 ms
92,000 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)

# 単純に橋となる辺を返す
def bridge(G, N):
    result = set()
    label = [None]*N
    gen = 0
    cost = [0]*N
    def dfs(u, p):
        nonlocal gen
        res = 0
        for v in G[u]:
            if v == p:
                continue
            if label[v] is not None:
                if label[v] < label[u]:
                    cost[v] += 1
                    res += 1
            else:
                label[v] = gen; gen += 1
                r = dfs(v, u)
                if r == 0:
                    result.add((u, v) if u < v else (v, u))
                res += r
        res -= cost[u]
        return res
    for v in range(N):
        if not label[v]:
            label[v] = gen; gen += 1
            r = dfs(v, -1)
            assert r == 0, r
    return result

ret = bridge(edge, n)

edge2 = [[] for _ in range(n)]
for u, v in ret:
    edge2[u].append(v)
    edge2[v].append(u)

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