結果

問題 No.2428 Returning Shuffle
ユーザー ntudantuda
提出日時 2023-08-19 10:21:25
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 763 bytes
コンパイル時間 890 ms
コンパイル使用メモリ 86,956 KB
実行使用メモリ 253,516 KB
最終ジャッジ日時 2023-08-19 10:21:37
合計ジャッジ時間 10,229 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 RE -
testcase_02 RE -
testcase_03 AC 61 ms
71,116 KB
testcase_04 AC 62 ms
71,164 KB
testcase_05 AC 59 ms
71,164 KB
testcase_06 WA -
testcase_07 AC 60 ms
70,980 KB
testcase_08 AC 64 ms
71,160 KB
testcase_09 WA -
testcase_10 AC 61 ms
70,748 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 70 ms
70,964 KB
testcase_15 AC 62 ms
70,956 KB
testcase_16 AC 60 ms
71,084 KB
testcase_17 AC 64 ms
71,168 KB
testcase_18 AC 62 ms
71,020 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 60 ms
71,148 KB
testcase_22 AC 61 ms
71,000 KB
testcase_23 AC 61 ms
71,080 KB
testcase_24 AC 592 ms
253,516 KB
testcase_25 AC 689 ms
253,328 KB
権限があれば一括ダウンロードができます

ソースコード

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):
    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 *= size(i)
print(ans)
0