結果

問題 No.2428 Returning Shuffle
ユーザー ntudantuda
提出日時 2023-08-19 10:48:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,009 ms / 2,000 ms
コード長 829 bytes
コンパイル時間 623 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 253,424 KB
最終ジャッジ日時 2023-08-19 10:48:32
合計ジャッジ時間 8,800 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 225 ms
95,140 KB
testcase_01 AC 719 ms
95,924 KB
testcase_02 AC 697 ms
95,568 KB
testcase_03 AC 60 ms
71,348 KB
testcase_04 AC 59 ms
71,492 KB
testcase_05 AC 59 ms
71,528 KB
testcase_06 AC 60 ms
71,456 KB
testcase_07 AC 62 ms
71,416 KB
testcase_08 AC 61 ms
71,304 KB
testcase_09 AC 61 ms
71,132 KB
testcase_10 AC 61 ms
71,460 KB
testcase_11 AC 60 ms
71,492 KB
testcase_12 AC 61 ms
71,328 KB
testcase_13 AC 83 ms
71,520 KB
testcase_14 AC 60 ms
71,204 KB
testcase_15 AC 59 ms
71,200 KB
testcase_16 AC 61 ms
71,208 KB
testcase_17 AC 61 ms
71,196 KB
testcase_18 AC 60 ms
71,456 KB
testcase_19 AC 489 ms
96,784 KB
testcase_20 AC 523 ms
98,096 KB
testcase_21 AC 61 ms
71,460 KB
testcase_22 AC 60 ms
71,480 KB
testcase_23 AC 60 ms
71,404 KB
testcase_24 AC 764 ms
252,516 KB
testcase_25 AC 1,009 ms
253,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353
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)
tmp = 1
for i in range(N):
    if i == root(i):
        s = size(i)
        tmp = lcm(tmp,s)
print(tmp % MOD)
0