結果

問題 No.2428 Returning Shuffle
ユーザー titiatitia
提出日時 2023-09-04 01:15:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,018 bytes
コンパイル時間 442 ms
コンパイル使用メモリ 10,940 KB
実行使用メモリ 194,248 KB
最終ジャッジ日時 2023-09-04 01:16:02
合計ジャッジ時間 9,772 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,998 ms
194,248 KB
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 #

import sys
input = sys.stdin.readline

mod=998244353

N,M=map(int,input().split())

P=list(range(N))
for i in range(M):
    A=list(map(int,input().split()))[1:]
    X=[]

    for a in A:
        X.append(P[a-1])

    for i in range(len(A)):
        P[A[i]-1]=X[i-1]

    #print(P)

# UnionFind

Group = [i for i in range(N+1)] # グループ分け
Nodes = [1]*(N+1) # 各グループのノードの数

def find(x):
    while Group[x] != x:
        x=Group[x]
    return x

def Union(x,y):
    if find(x) != find(y):
        if Nodes[find(x)] < Nodes[find(y)]:
            
            Nodes[find(y)] += Nodes[find(x)]
            Nodes[find(x)] = 0
            Group[find(x)] = find(y)
            
        else:
            Nodes[find(x)] += Nodes[find(y)]
            Nodes[find(y)] = 0
            Group[find(y)] = find(x)

for i in range(N):
    Union(i,P[i])

from math import gcd

def lcm(x,y):
    return x*y//gcd(x,y)

ANS=1
for i in range(N):
    if find(i)==i:
        ANS=lcm(ANS,Nodes[i])

print(ANS%mod)
0