結果

問題 No.2428 Returning Shuffle
ユーザー ntudantuda
提出日時 2023-08-19 10:06:55
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 665 bytes
コンパイル時間 900 ms
コンパイル使用メモリ 86,776 KB
実行使用メモリ 536,400 KB
最終ジャッジ日時 2023-08-19 10:07:04
合計ジャッジ時間 8,943 ms
ジャッジサーバーID
(参考情報)
judge12 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0