結果

問題 No.2428 Returning Shuffle
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2023-08-18 22:36:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,093 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 256,420 KB
最終ジャッジ日時 2024-05-06 04:56:41
合計ジャッジ時間 5,898 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 36 ms
52,224 KB
testcase_04 AC 35 ms
51,968 KB
testcase_05 AC 34 ms
52,352 KB
testcase_06 WA -
testcase_07 AC 34 ms
52,224 KB
testcase_08 AC 34 ms
52,608 KB
testcase_09 WA -
testcase_10 AC 33 ms
52,352 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 35 ms
52,096 KB
testcase_15 AC 35 ms
52,736 KB
testcase_16 AC 35 ms
51,968 KB
testcase_17 AC 34 ms
52,224 KB
testcase_18 AC 34 ms
52,224 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 37 ms
51,968 KB
testcase_22 AC 36 ms
52,352 KB
testcase_23 AC 36 ms
52,608 KB
testcase_24 AC 680 ms
256,092 KB
testcase_25 AC 583 ms
256,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Unionfind:
     
    def __init__(self,n):
        self.uf = [-1]*n
 
    def find(self,x):
        if self.uf[x] < 0:
            return x
        else:
            self.uf[x] = self.find(self.uf[x])
            return self.uf[x]
 
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.uf[x] > self.uf[y]:
            x,y = y,x
        self.uf[x] += self.uf[y]
        self.uf[y] = x
        return True
 
    def size(self,x):
        x = self.find(x)
        return -self.uf[x]

n,m = map(int,input().split())
mod = 998244353

P = [i for i in range(n)]

for _ in range(m):
    t,*S = map(int,input().split())

    S = [s-1 for s in S]
    rec = P[S[-1]]

    for i in range(t-1)[::-1]:
        x = S[i]
        nx = S[i+1]
        P[nx] = P[x]
    P[S[0]] = rec

uf = Unionfind(n)

for i,p in enumerate(P):
    uf.union(i,p)


ans = 1
for i in range(n):
    if uf.find(i) == i:
        ans *= uf.size(i)
        ans %= mod
print(ans)
0