結果
問題 | No.2428 Returning Shuffle |
ユーザー |
![]() |
提出日時 | 2023-08-19 10:24:11 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 793 bytes |
コンパイル時間 | 284 ms |
コンパイル使用メモリ | 82,496 KB |
実行使用メモリ | 245,796 KB |
最終ジャッジ日時 | 2024-11-29 01:52:30 |
合計ジャッジ時間 | 6,423 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 WA * 5 |
ソースコード
from math import lcmdef root(x):if P[x] < 0: return xP[x] = root(P[x]) # 経路圧縮return P[x]def unite(x, y):x = root(x)y = root(y)if x == y: returnif x > y: x, y = y, xP[x] += P[y]P[y] = xdef 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] * NP1 = 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] = s0continueP1[S[(i + 1) % t] - 1] = P1[S[i] - 1]for i, p in enumerate(P1):unite(i, p)ans = 1for i in range(N):if i == root(i):ans = lcm(ans,size(i))print(ans)