結果
| 問題 |
No.2494 Sum within Components
|
| コンテスト | |
| ユーザー |
mymelochan
|
| 提出日時 | 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 sys
sys.setrecursionlimit(10**7)
from heapq import heappop,heappush
from collections import deque,defaultdict,Counter
from bisect import bisect_left, bisect_right
from itertools import product,combinations,permutations
ipt = sys.stdin.readline
def iin():
return int(ipt())
def lmin():
return list(map(int,ipt().split()))
class dsu:
def __init__(self,n):
self.N = n
self.cnt=[1]*self.N
self.root=list(range(self.N))
self.components = self.N
def unite(self,x,y):
x=self.leader(x)
y=self.leader(y)
if x!=y:
self.components -= 1
if self.cnt[x]<self.cnt[y]:
x,y=y,x
self.cnt[x]+=self.cnt[y]
self.root[y]=x
return x
return None
def leader(self,x):
if self.root[x]==x:
return x
self.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-1
uf.unite(u,v)
cnt = [0]*N
for i in range(N):
l = uf.leader(i)
cnt[l] += A[i]
cnt[l] %= MOD
ans = 1
for i in range(N):
ans *= cnt[uf.leader(i)]
ans %= MOD
print(ans)
mymelochan