結果

問題 No.2428 Returning Shuffle
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2023-08-24 21:02:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,340 ms / 2,000 ms
コード長 2,913 bytes
コンパイル時間 1,042 ms
コンパイル使用メモリ 86,832 KB
実行使用メモリ 335,980 KB
最終ジャッジ日時 2023-08-24 21:02:40
合計ジャッジ時間 13,188 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 503 ms
172,732 KB
testcase_01 AC 1,310 ms
247,828 KB
testcase_02 AC 1,340 ms
249,528 KB
testcase_03 AC 177 ms
101,000 KB
testcase_04 AC 174 ms
100,888 KB
testcase_05 AC 173 ms
101,124 KB
testcase_06 AC 176 ms
101,084 KB
testcase_07 AC 202 ms
101,196 KB
testcase_08 AC 174 ms
100,948 KB
testcase_09 AC 177 ms
101,216 KB
testcase_10 AC 172 ms
101,156 KB
testcase_11 AC 176 ms
100,888 KB
testcase_12 AC 174 ms
101,092 KB
testcase_13 AC 204 ms
101,016 KB
testcase_14 AC 176 ms
101,064 KB
testcase_15 AC 174 ms
100,792 KB
testcase_16 AC 176 ms
101,012 KB
testcase_17 AC 176 ms
101,156 KB
testcase_18 AC 172 ms
101,012 KB
testcase_19 AC 1,080 ms
235,560 KB
testcase_20 AC 1,071 ms
230,728 KB
testcase_21 AC 173 ms
101,052 KB
testcase_22 AC 201 ms
100,768 KB
testcase_23 AC 175 ms
101,120 KB
testcase_24 AC 920 ms
328,072 KB
testcase_25 AC 941 ms
335,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
input = sys.stdin.readline

N,M = map(int,input().split())
class DSU:
    def __init__(self, n):
        self._n = n
        self.parent_or_size = [-1] * n

    def merge(self, a, b):
        assert 0 <= a < self._n
        assert 0 <= b < self._n
        x, y = self.leader(a), self.leader(b)
        if x == y: return x
        if -self.parent_or_size[x] < -self.parent_or_size[y]: x, y = y, x
        self.parent_or_size[x] += self.parent_or_size[y]
        self.parent_or_size[y] = x
        return x

    def same(self, a, b):
        assert 0 <= a < self._n
        assert 0 <= b < self._n
        return self.leader(a) == self.leader(b)

    def leader(self, a):
        assert 0 <= a < self._n
        if self.parent_or_size[a] < 0: return a
        self.parent_or_size[a] = self.leader(self.parent_or_size[a])
        return self.parent_or_size[a]

    def size(self, a):
        assert 0 <= a < self._n
        return -self.parent_or_size[self.leader(a)]

    def groups(self):
        leader_buf = [self.leader(i) for i in range(self._n)]
        result = [[] for _ in range(self._n)]
        for i in range(self._n): result[leader_buf[i]].append(i)
        return [r for r in result if r != []]

class prime_factorize():
    
    def __init__(self,M=10**6):
        self.sieve = [-1]*(M+1)
        self.sieve[1] = 1
        self.p = [False]*(M+1)
        self.mu = [1]*(M+1)
        
        for i in range(2,M+1):
            if self.sieve[i] == -1:
                self.p[i] = True
                
                i2 = i**2
                for j in range(i2,M+1,i2):
                    
                    self.mu[j] = 0
                
                
                for j in range(i,M+1,i):
                    self.sieve[j] = i
                    
                    self.mu[j] *= -1
                    
    def factors(self,x):
        tmp = []
        while self.sieve[x] != x:
            tmp.append(self.sieve[x])
            x //= self.sieve[x]
        tmp.append(self.sieve[x])
        return tmp
        
    def is_prime(self,x):
        return self.p[x]
        
    def mobius(self,x):
        return self.mu[x]
        
pf = prime_factorize()



X = [i for i in range(N)]
for _ in range(M):
    
    t,*S = map(int,input().split())
    Y = []
    for j in range(t):
        s0 = S[j]-1
        # s1 = S[(j+1)%t]-1
        Y.append(X[s0])
    for j in range(t):
        s1 = S[(j+1)%t]-1
        X[s1] = Y[j]

# print(X)        
        
D = DSU(N)
for i,s in enumerate(X):
    D.merge(i,s)
    
X = [len(g) for g in D.groups()]

V = defaultdict(int)

for x in X:
    
    for k,v in Counter(pf.factors(x)).items():
        
        V[k] = max(V[k],v)
        
mod = 998244353

ans = 1
for k,v in V.items():
    ans *= pow(k,v,mod)
    ans %= mod
print(ans)
    
    
0