結果

問題 No.101 ぐるぐる!あみだくじ!
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-26 23:53:01
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 594 bytes
コンパイル時間 199 ms
コンパイル使用メモリ 81,756 KB
実行使用メモリ 53,716 KB
最終ジャッジ日時 2023-10-25 08:43:19
合計ジャッジ時間 3,536 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,484 KB
testcase_01 AC 40 ms
53,484 KB
testcase_02 AC 40 ms
53,484 KB
testcase_03 AC 38 ms
53,484 KB
testcase_04 WA -
testcase_05 AC 40 ms
53,484 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 39 ms
53,484 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 38 ms
53,484 KB
testcase_35 AC 38 ms
53,484 KB
testcase_36 AC 38 ms
53,484 KB
testcase_37 AC 38 ms
53,484 KB
testcase_38 AC 38 ms
53,484 KB
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
*num, = range(N)

K = int(input())
for _ in range(K):
    x, y = map(int, input().split())
    y -= 2
    num[x], num[y] = num[y], num[x]

seen = [0] * N
loop = []
for i in range(N):
    cnt = 0
    while not seen[i]:
        seen[i] = 1
        cnt += 1
        i = num[i]
    if cnt:
        loop.append(cnt)

if not loop:
    print(1)
else:
    from math import gcd
    g = 0
    for x in loop:
        g = gcd(g, x)
    ans = 1
    for x in loop:
        ans *= x // g
    ans *= g
    print(ans)
0