結果
問題 | No.1983 [Cherry 4th Tune C] 南の島のマーメイド |
ユーザー | neginagi |
提出日時 | 2022-08-28 13:55:23 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,625 ms / 4,000 ms |
コード長 | 1,932 bytes |
コンパイル時間 | 338 ms |
コンパイル使用メモリ | 82,356 KB |
実行使用メモリ | 337,732 KB |
最終ジャッジ日時 | 2024-10-15 12:45:39 |
合計ジャッジ時間 | 28,339 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 129 ms
86,272 KB |
testcase_01 | AC | 131 ms
86,392 KB |
testcase_02 | AC | 136 ms
86,272 KB |
testcase_03 | AC | 127 ms
86,396 KB |
testcase_04 | AC | 126 ms
86,624 KB |
testcase_05 | AC | 126 ms
86,272 KB |
testcase_06 | AC | 129 ms
86,400 KB |
testcase_07 | AC | 128 ms
86,272 KB |
testcase_08 | AC | 197 ms
91,008 KB |
testcase_09 | AC | 196 ms
90,880 KB |
testcase_10 | AC | 206 ms
93,952 KB |
testcase_11 | AC | 223 ms
95,872 KB |
testcase_12 | AC | 209 ms
91,264 KB |
testcase_13 | AC | 611 ms
135,020 KB |
testcase_14 | AC | 648 ms
150,656 KB |
testcase_15 | AC | 713 ms
143,232 KB |
testcase_16 | AC | 333 ms
114,816 KB |
testcase_17 | AC | 676 ms
156,672 KB |
testcase_18 | AC | 643 ms
140,672 KB |
testcase_19 | AC | 1,045 ms
222,592 KB |
testcase_20 | AC | 671 ms
140,032 KB |
testcase_21 | AC | 722 ms
155,392 KB |
testcase_22 | AC | 859 ms
181,248 KB |
testcase_23 | AC | 1,263 ms
260,224 KB |
testcase_24 | AC | 1,182 ms
243,584 KB |
testcase_25 | AC | 1,022 ms
190,208 KB |
testcase_26 | AC | 1,280 ms
221,056 KB |
testcase_27 | AC | 1,303 ms
266,752 KB |
testcase_28 | AC | 1,245 ms
220,416 KB |
testcase_29 | AC | 1,625 ms
298,880 KB |
testcase_30 | AC | 1,244 ms
220,800 KB |
testcase_31 | AC | 1,227 ms
220,928 KB |
testcase_32 | AC | 1,235 ms
220,888 KB |
testcase_33 | AC | 126 ms
86,528 KB |
testcase_34 | AC | 267 ms
107,008 KB |
testcase_35 | AC | 696 ms
308,992 KB |
testcase_36 | AC | 368 ms
124,996 KB |
testcase_37 | AC | 128 ms
86,272 KB |
testcase_38 | AC | 198 ms
89,600 KB |
testcase_39 | AC | 871 ms
337,732 KB |
testcase_40 | AC | 464 ms
172,328 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")