結果

問題 No.101 ぐるぐる!あみだくじ!
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2023-06-08 12:19:32
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,649 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 87,300 KB
実行使用メモリ 73,268 KB
最終ジャッジ日時 2023-08-29 01:45:17
合計ジャッジ時間 7,899 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
73,004 KB
testcase_01 AC 109 ms
72,772 KB
testcase_02 AC 113 ms
72,916 KB
testcase_03 AC 107 ms
72,824 KB
testcase_04 WA -
testcase_05 AC 108 ms
72,772 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 110 ms
72,944 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 110 ms
72,504 KB
testcase_35 AC 110 ms
72,868 KB
testcase_36 AC 108 ms
72,820 KB
testcase_37 AC 108 ms
72,672 KB
testcase_38 AC 110 ms
72,680 KB
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0