結果
問題 | No.101 ぐるぐる!あみだくじ! |
ユーザー | Navier_Boltzmann |
提出日時 | 2023-06-08 12:19:32 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,649 bytes |
コンパイル時間 | 164 ms |
コンパイル使用メモリ | 82,340 KB |
実行使用メモリ | 59,564 KB |
最終ジャッジ日時 | 2024-06-09 19:57:44 |
合計ジャッジ時間 | 3,083 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
56,892 KB |
testcase_01 | AC | 47 ms
58,676 KB |
testcase_02 | AC | 43 ms
59,564 KB |
testcase_03 | AC | 40 ms
56,940 KB |
testcase_04 | WA | - |
testcase_05 | AC | 47 ms
59,008 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 41 ms
56,856 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | AC | 41 ms
56,560 KB |
testcase_35 | AC | 38 ms
57,536 KB |
testcase_36 | AC | 40 ms
56,028 KB |
testcase_37 | AC | 40 ms
57,188 KB |
testcase_38 | AC | 40 ms
56,916 KB |
testcase_39 | WA | - |
ソースコード
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 = [len(g) for g in D.groups()] d = A[0] if len(A)==1: print(A[0]) exit() M = 1 for a in A: M *= a d = math.gcd(d,a) print(M//d)