結果
| 問題 | 
                            No.2494 Sum within Components
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2023-10-07 00:05:58 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 382 ms / 2,000 ms | 
| コード長 | 2,085 bytes | 
| コンパイル時間 | 261 ms | 
| コンパイル使用メモリ | 82,524 KB | 
| 実行使用メモリ | 136,088 KB | 
| 最終ジャッジ日時 | 2024-07-26 17:29:16 | 
| 合計ジャッジ時間 | 3,785 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 17 | 
ソースコード
import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline
from collections import defaultdict, deque, Counter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
from math import gcd
from itertools import product, permutations
#重複あり:list(product(list('123'),repeat = 2)),重複なし:list(permutations(list('123')))
MOD = 998244353
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())
    def group(self):
        group_members = defaultdict(list)
        for member in range(self.n):
            group_members[self.find(member)].append(member)
        return group_members
    def __str__(self):
        return ''.join(f'{r}: {m}' for r, m in self.group().items())
n,m = map(int,input().split())
l = list(map(int,input().split()))
uf = UnionFind(n)
graph = [[] for i in range(n+1)]
e=[]
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
    e.append([a,b])
    uf.union(a,b)
d = defaultdict(int)
for i in range(n):
    ii = uf.find(i)
    d[ii] += l[i]
    d[ii] %= MOD
ans = 1
for i in range(n):
    ii = uf.find(i)
    ans *= d[ii]
    ans %= MOD
print(ans)