結果
問題 | No.1983 [Cherry 4th Tune C] 南の島のマーメイド |
ユーザー | strangerxxx |
提出日時 | 2022-08-30 09:30:48 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,481 bytes |
コンパイル時間 | 132 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 56,576 KB |
最終ジャッジ日時 | 2024-11-07 04:30:29 |
合計ジャッジ時間 | 60,351 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
11,136 KB |
testcase_01 | AC | 31 ms
11,136 KB |
testcase_02 | AC | 31 ms
11,008 KB |
testcase_03 | AC | 31 ms
11,136 KB |
testcase_04 | AC | 32 ms
11,136 KB |
testcase_05 | AC | 31 ms
11,008 KB |
testcase_06 | AC | 32 ms
11,008 KB |
testcase_07 | AC | 32 ms
11,008 KB |
testcase_08 | AC | 81 ms
11,392 KB |
testcase_09 | AC | 109 ms
12,160 KB |
testcase_10 | AC | 115 ms
12,800 KB |
testcase_11 | AC | 133 ms
12,672 KB |
testcase_12 | AC | 90 ms
11,776 KB |
testcase_13 | AC | 1,572 ms
29,952 KB |
testcase_14 | AC | 1,765 ms
32,896 KB |
testcase_15 | AC | 1,900 ms
39,808 KB |
testcase_16 | AC | 1,043 ms
29,824 KB |
testcase_17 | AC | 1,746 ms
34,048 KB |
testcase_18 | AC | 1,525 ms
39,936 KB |
testcase_19 | AC | 1,666 ms
46,208 KB |
testcase_20 | AC | 1,669 ms
37,888 KB |
testcase_21 | WA | - |
testcase_22 | AC | 1,760 ms
40,576 KB |
testcase_23 | AC | 2,572 ms
48,896 KB |
testcase_24 | AC | 2,488 ms
48,768 KB |
testcase_25 | AC | 2,474 ms
48,768 KB |
testcase_26 | AC | 2,473 ms
48,896 KB |
testcase_27 | AC | 2,486 ms
48,768 KB |
testcase_28 | AC | 2,466 ms
48,768 KB |
testcase_29 | WA | - |
testcase_30 | AC | 2,479 ms
48,768 KB |
testcase_31 | AC | 2,745 ms
48,768 KB |
testcase_32 | AC | 2,444 ms
48,768 KB |
testcase_33 | AC | 31 ms
11,008 KB |
testcase_34 | AC | 1,443 ms
28,288 KB |
testcase_35 | AC | 2,119 ms
47,104 KB |
testcase_36 | AC | 2,106 ms
47,104 KB |
testcase_37 | AC | 31 ms
11,008 KB |
testcase_38 | WA | - |
testcase_39 | AC | 2,371 ms
47,104 KB |
testcase_40 | AC | 2,471 ms
56,576 KB |
ソースコード
def resolve(): n, m, q = map(int, input().split()) edges = [[] for _ in range(n)] for _ in range(m): u, v = map(lambda x: int(x) - 1, input().split()) edges[u].append(v) edges[v].append(u) u = decompositon(edges) for _ in range(q): x, y = map(lambda x: int(x) - 1, input().split()) if u.same(x, y): print("Yes") else: print("No") def decompositon(edges): in_cnt = [len(x) for x in edges] q = [i for i, x in enumerate(in_cnt) if x == 1] u = UnionFind(len(edges)) while q: i = q.pop() for j in edges[i]: u.union(i, j) in_cnt[j] -= 1 if in_cnt[j] == 1: q.append(j) return u class UnionFind: def __init__(self, n: int) -> None: self.n = n self.parent = [-1] * n self.groups = n def find(self, x: int) -> int: if self.parent[x] < 0: return x else: p = x while self.parent[p] >= 0: p = self.parent[p] while self.parent[x] >= 0: self.parent[x], x = p, self.parent[x] return p def union(self, x: int, y: int) -> bool: x = self.find(x) y = self.find(y) if x == y: return False if self.parent[x] > self.parent[y]: x, y = y, x self.parent[x] += self.parent[y] self.parent[y] = x self.groups -= 1 return True def size(self, x: int) -> int: return -self.parent[self.find(x)] def same(self, x: int, y: int) -> bool: return self.find(x) == self.find(y) def members(self, x: int) -> list: root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self) -> list: return [i for i, x in enumerate(self.parent) if x < 0] def group_count(self) -> int: return self.groups def sizes(self) -> dict: return {i: -x for i, x in enumerate(self.parent) if x < 0} def all_group_members(self) -> dict: from collections import defaultdict d = defaultdict(list) for i in range(self.n): p = self.find(i) d[p].append(i) return d def __str__(self) -> str: return '\n'.join('{}: {}'.format(k, v) for k, v in self.all_group_members().items()) if __name__ == '__main__': resolve()