結果
問題 | No.2494 Sum within Components |
ユーザー |
![]() |
提出日時 | 2023-10-06 21:38:28 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 243 ms / 2,000 ms |
コード長 | 1,364 bytes |
コンパイル時間 | 167 ms |
コンパイル使用メモリ | 82,596 KB |
実行使用メモリ | 106,892 KB |
最終ジャッジ日時 | 2024-07-26 15:52:23 |
合計ジャッジ時間 | 2,971 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#############################################################import syssys.setrecursionlimit(10**7)from heapq import heappop,heappushfrom collections import deque,defaultdict,Counterfrom bisect import bisect_left, bisect_rightfrom itertools import product,combinations,permutationsipt = sys.stdin.readlinedef iin():return int(ipt())def lmin():return list(map(int,ipt().split()))class dsu:def __init__(self,n):self.N = nself.cnt=[1]*self.Nself.root=list(range(self.N))self.components = self.Ndef unite(self,x,y):x=self.leader(x)y=self.leader(y)if x!=y:self.components -= 1if self.cnt[x]<self.cnt[y]:x,y=y,xself.cnt[x]+=self.cnt[y]self.root[y]=xreturn xreturn Nonedef leader(self,x):if self.root[x]==x:return xself.root[x]=self.leader(self.root[x])return self.root[x]MOD = 998244353#############################################################N,M = lmin()A = lmin()uf = dsu(N)for _ in range(M):u,v = lmin()u,v = u-1,v-1uf.unite(u,v)cnt = [0]*Nfor i in range(N):l = uf.leader(i)cnt[l] += A[i]cnt[l] %= MODans = 1for i in range(N):ans *= cnt[uf.leader(i)]ans %= MODprint(ans)