結果
| 問題 |
No.2428 Returning Shuffle
|
| コンテスト | |
| ユーザー |
ntuda
|
| 提出日時 | 2023-08-19 10:06:55 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 665 bytes |
| コンパイル時間 | 321 ms |
| コンパイル使用メモリ | 82,312 KB |
| 実行使用メモリ | 512,404 KB |
| 最終ジャッジ日時 | 2024-11-29 01:33:32 |
| 合計ジャッジ時間 | 19,933 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 WA * 6 TLE * 4 MLE * 1 |
ソースコード
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):
P2 = P1[:]
t,*S = map(int,input().split())
S.append(S[0])
for i in range(len(S)-1):
P2[S[i+1]-1] = P1[S[i]-1]
P1 = P2
for i,p in enumerate(P1):
unite(i,p)
tmp = 1
for i in range(N):
if i == root(i):
tmp *= size(i)
print(tmp)
ntuda