結果
問題 | No.1983 [Cherry 4th Tune C] 南の島のマーメイド |
ユーザー | neginagi |
提出日時 | 2022-08-28 13:55:59 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 2,156 ms / 4,000 ms |
コード長 | 1,932 bytes |
コンパイル時間 | 399 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 102,784 KB |
最終ジャッジ日時 | 2024-10-15 12:47:00 |
合計ジャッジ時間 | 48,218 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
11,392 KB |
testcase_01 | AC | 35 ms
11,520 KB |
testcase_02 | AC | 35 ms
11,520 KB |
testcase_03 | AC | 35 ms
11,392 KB |
testcase_04 | AC | 35 ms
11,392 KB |
testcase_05 | AC | 36 ms
11,392 KB |
testcase_06 | AC | 36 ms
11,392 KB |
testcase_07 | AC | 35 ms
11,392 KB |
testcase_08 | AC | 58 ms
12,288 KB |
testcase_09 | AC | 79 ms
13,568 KB |
testcase_10 | AC | 93 ms
14,456 KB |
testcase_11 | AC | 96 ms
14,584 KB |
testcase_12 | AC | 68 ms
13,056 KB |
testcase_13 | AC | 1,126 ms
45,496 KB |
testcase_14 | AC | 1,289 ms
47,636 KB |
testcase_15 | AC | 1,594 ms
66,388 KB |
testcase_16 | AC | 873 ms
48,640 KB |
testcase_17 | AC | 1,306 ms
48,592 KB |
testcase_18 | AC | 1,463 ms
67,232 KB |
testcase_19 | AC | 1,807 ms
74,068 KB |
testcase_20 | AC | 1,448 ms
63,104 KB |
testcase_21 | AC | 1,386 ms
56,784 KB |
testcase_22 | AC | 1,481 ms
58,752 KB |
testcase_23 | AC | 2,114 ms
73,728 KB |
testcase_24 | AC | 2,135 ms
73,852 KB |
testcase_25 | AC | 2,152 ms
73,796 KB |
testcase_26 | AC | 2,117 ms
73,992 KB |
testcase_27 | AC | 2,114 ms
73,864 KB |
testcase_28 | AC | 2,143 ms
73,840 KB |
testcase_29 | AC | 2,134 ms
73,792 KB |
testcase_30 | AC | 2,128 ms
73,840 KB |
testcase_31 | AC | 2,140 ms
73,824 KB |
testcase_32 | AC | 2,156 ms
73,864 KB |
testcase_33 | AC | 36 ms
11,520 KB |
testcase_34 | AC | 967 ms
47,416 KB |
testcase_35 | AC | 1,437 ms
102,656 KB |
testcase_36 | AC | 1,309 ms
66,368 KB |
testcase_37 | AC | 35 ms
11,392 KB |
testcase_38 | AC | 412 ms
11,648 KB |
testcase_39 | AC | 1,842 ms
102,784 KB |
testcase_40 | AC | 1,797 ms
91,872 KB |
ソースコード
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")