結果

問題 No.2428 Returning Shuffle
ユーザー ntudantuda
提出日時 2023-08-19 10:24:11
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 793 bytes
コンパイル時間 656 ms
コンパイル使用メモリ 87,004 KB
実行使用メモリ 254,712 KB
最終ジャッジ日時 2023-08-19 10:24:22
合計ジャッジ時間 9,014 ms
ジャッジサーバーID
(参考情報)
judge12 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 73 ms
71,488 KB
testcase_04 AC 72 ms
71,484 KB
testcase_05 AC 73 ms
71,704 KB
testcase_06 AC 72 ms
71,220 KB
testcase_07 AC 70 ms
71,668 KB
testcase_08 AC 70 ms
71,328 KB
testcase_09 AC 72 ms
71,664 KB
testcase_10 AC 71 ms
71,376 KB
testcase_11 AC 71 ms
71,260 KB
testcase_12 AC 70 ms
71,256 KB
testcase_13 AC 75 ms
71,664 KB
testcase_14 AC 72 ms
71,188 KB
testcase_15 AC 71 ms
71,628 KB
testcase_16 AC 72 ms
71,504 KB
testcase_17 AC 71 ms
71,184 KB
testcase_18 AC 73 ms
71,216 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 70 ms
71,556 KB
testcase_22 AC 71 ms
71,284 KB
testcase_23 AC 71 ms
71,320 KB
testcase_24 AC 681 ms
254,712 KB
testcase_25 AC 678 ms
253,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import lcm

def root(x):
    if P[x] < 0: return x
    P[x] = root(P[x])  # 経路圧縮
    return P[x]

def unite(x, y):
    x = root(x)
    y = root(y)
    if x == y: return
    if x > y: x, y = y, x
    P[x] += P[y]
    P[y] = x

def same(x, y):
    return root(x) == root(y)

def size(x):
    x = root(x)
    return -P[x]


N, M = map(int, input().split())
P = [-1] * N

P1 = list(range(N))
for _ in range(M):
    t, *S = map(int, input().split())
    s0 = P1[S[0] - 1]
    n = len(S)
    for i in reversed(range(n)):
        if i == 0:
            P1[S[(i + 1) % t] - 1] = s0
            continue
        P1[S[(i + 1) % t] - 1] = P1[S[i] - 1]

for i, p in enumerate(P1):
    unite(i, p)
ans = 1
for i in range(N):
    if i == root(i):
        ans = lcm(ans,size(i))
print(ans)
0