結果

問題 No.101 ぐるぐる!あみだくじ!
ユーザー maspymaspy
提出日時 2020-03-05 10:36:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 23 ms / 5,000 ms
コード長 700 bytes
コンパイル時間 149 ms
コンパイル使用メモリ 10,908 KB
実行使用メモリ 8,996 KB
最終ジャッジ日時 2023-08-04 03:47:08
合計ジャッジ時間 3,691 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
8,728 KB
testcase_01 AC 22 ms
8,688 KB
testcase_02 AC 22 ms
8,844 KB
testcase_03 AC 20 ms
8,696 KB
testcase_04 AC 21 ms
8,724 KB
testcase_05 AC 21 ms
8,676 KB
testcase_06 AC 21 ms
8,732 KB
testcase_07 AC 21 ms
8,712 KB
testcase_08 AC 22 ms
8,864 KB
testcase_09 AC 22 ms
8,712 KB
testcase_10 AC 20 ms
8,840 KB
testcase_11 AC 21 ms
8,936 KB
testcase_12 AC 21 ms
8,924 KB
testcase_13 AC 21 ms
8,768 KB
testcase_14 AC 22 ms
8,948 KB
testcase_15 AC 21 ms
8,928 KB
testcase_16 AC 21 ms
8,940 KB
testcase_17 AC 22 ms
8,748 KB
testcase_18 AC 21 ms
8,908 KB
testcase_19 AC 22 ms
8,912 KB
testcase_20 AC 22 ms
8,772 KB
testcase_21 AC 22 ms
8,896 KB
testcase_22 AC 21 ms
8,776 KB
testcase_23 AC 23 ms
8,768 KB
testcase_24 AC 21 ms
8,840 KB
testcase_25 AC 21 ms
8,804 KB
testcase_26 AC 22 ms
8,764 KB
testcase_27 AC 21 ms
8,788 KB
testcase_28 AC 22 ms
8,888 KB
testcase_29 AC 22 ms
8,768 KB
testcase_30 AC 21 ms
8,804 KB
testcase_31 AC 22 ms
8,996 KB
testcase_32 AC 22 ms
8,740 KB
testcase_33 AC 21 ms
8,820 KB
testcase_34 AC 21 ms
8,828 KB
testcase_35 AC 20 ms
8,824 KB
testcase_36 AC 21 ms
8,860 KB
testcase_37 AC 21 ms
8,860 KB
testcase_38 AC 21 ms
8,692 KB
testcase_39 AC 21 ms
8,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from math import gcd
from functools import reduce

# %%
N = int(readline())
K = int(readline())
m = map(int, read().split())
XY = zip(m, m)


# %%
P = list(range(N))
for x, y in XY:
    x -= 1
    y -= 1
    P[x], P[y] = P[y], P[x]


# %%
comp = [0] * N
size = []
n = 0
for i in range(N):
    if comp[i]:
        continue
    n += 1
    comp[i] = n
    s = 1
    while True:
        i = P[i]
        if comp[i]:
            break
        comp[i] = n
        s += 1
    size.append(s)


# %%
lcm = reduce(lambda x, y: x * (y // gcd(x, y)), size)
print(lcm)
0