結果
問題 | No.101 ぐるぐる!あみだくじ! |
ユーザー | Navier_Boltzmann |
提出日時 | 2023-06-08 12:22:06 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 54 ms / 5,000 ms |
コード長 | 1,737 bytes |
コンパイル時間 | 156 ms |
コンパイル使用メモリ | 82,648 KB |
実行使用メモリ | 64,160 KB |
最終ジャッジ日時 | 2024-06-09 19:58:18 |
合計ジャッジ時間 | 3,307 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
56,076 KB |
testcase_01 | AC | 48 ms
57,916 KB |
testcase_02 | AC | 48 ms
58,456 KB |
testcase_03 | AC | 51 ms
61,896 KB |
testcase_04 | AC | 45 ms
57,388 KB |
testcase_05 | AC | 49 ms
57,940 KB |
testcase_06 | AC | 46 ms
57,316 KB |
testcase_07 | AC | 54 ms
57,028 KB |
testcase_08 | AC | 48 ms
57,456 KB |
testcase_09 | AC | 48 ms
57,408 KB |
testcase_10 | AC | 52 ms
57,364 KB |
testcase_11 | AC | 50 ms
58,372 KB |
testcase_12 | AC | 52 ms
63,768 KB |
testcase_13 | AC | 49 ms
57,728 KB |
testcase_14 | AC | 47 ms
57,952 KB |
testcase_15 | AC | 48 ms
59,344 KB |
testcase_16 | AC | 48 ms
58,564 KB |
testcase_17 | AC | 47 ms
58,384 KB |
testcase_18 | AC | 48 ms
57,268 KB |
testcase_19 | AC | 52 ms
64,104 KB |
testcase_20 | AC | 48 ms
57,140 KB |
testcase_21 | AC | 49 ms
57,892 KB |
testcase_22 | AC | 48 ms
58,300 KB |
testcase_23 | AC | 49 ms
58,396 KB |
testcase_24 | AC | 49 ms
63,620 KB |
testcase_25 | AC | 49 ms
58,732 KB |
testcase_26 | AC | 52 ms
63,984 KB |
testcase_27 | AC | 52 ms
63,308 KB |
testcase_28 | AC | 52 ms
63,236 KB |
testcase_29 | AC | 52 ms
63,424 KB |
testcase_30 | AC | 52 ms
64,160 KB |
testcase_31 | AC | 52 ms
63,864 KB |
testcase_32 | AC | 47 ms
58,684 KB |
testcase_33 | AC | 52 ms
63,544 KB |
testcase_34 | AC | 47 ms
56,888 KB |
testcase_35 | AC | 46 ms
57,628 KB |
testcase_36 | AC | 46 ms
57,452 KB |
testcase_37 | AC | 50 ms
62,784 KB |
testcase_38 | AC | 48 ms
62,204 KB |
testcase_39 | AC | 48 ms
61,956 KB |
ソースコード
from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline class DSU: def __init__(self, n): self._n = n self.parent_or_size = [-1] * n def merge(self, a, b): assert 0 <= a < self._n assert 0 <= b < self._n x, y = self.leader(a), self.leader(b) if x == y: return x if -self.parent_or_size[x] < -self.parent_or_size[y]: x, y = y, x self.parent_or_size[x] += self.parent_or_size[y] self.parent_or_size[y] = x return x def same(self, a, b): assert 0 <= a < self._n assert 0 <= b < self._n return self.leader(a) == self.leader(b) def leader(self, a): assert 0 <= a < self._n if self.parent_or_size[a] < 0: return a self.parent_or_size[a] = self.leader(self.parent_or_size[a]) return self.parent_or_size[a] def size(self, a): assert 0 <= a < self._n return -self.parent_or_size[self.leader(a)] def groups(self): leader_buf = [self.leader(i) for i in range(self._n)] result = [[] for _ in range(self._n)] for i in range(self._n): result[leader_buf[i]].append(i) return [r for r in result if r != []] N = int(input()) K = int(input()) D = DSU(N) X = [i for i in range(N)] for _ in range(K): x,y = map(int,input().split()) x -= 1 y -= 1 X[x],X[y] = X[y],X[x] for i,x in enumerate(X): D.merge(i,x) A = [] for i in range(N): now = i cnt = 1 while X[now]!=i: now = X[now] cnt += 1 A.append(cnt) def lcm(x,y): return x*y//math.gcd(x,y) ans = 1 for a in A: ans = lcm(ans,a) print(ans)