結果
| 問題 | 
                            No.2494 Sum within Components
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2023-10-06 23:29:00 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,098 bytes | 
| コンパイル時間 | 218 ms | 
| コンパイル使用メモリ | 12,800 KB | 
| 実行使用メモリ | 65,696 KB | 
| 最終ジャッジ日時 | 2024-07-26 17:08:42 | 
| 合計ジャッジ時間 | 7,472 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 15 WA * 2 | 
ソースコード
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
n,m = map(int,input().split())
l = list(map(int,input().split()))
graph = [[]*m for _ in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    a-=1
    b-=1
    graph[a].append(b)
    graph[b].append(a)
def dfs(crr, v):
    v[crr] = True
    road_s.add(crr)
    road_l.append(crr)
    for nxt in graph[crr]:
        if v[nxt]:continue
        dfs(nxt, v)
    #v[crr] = False
    #road.pop(crr)
ans=1
visit=set()
vi=[False]*n
for i in range(n):
    if i in visit:continue
    road_s = set()
    road_l = []
    dfs(i,vi)
    visit |= road_s
    aa=0
    nn = len(road_l)
    #print(road_l)
    for j in road_l:
        aa += l[j]
    if aa:
        ans *= aa ** nn
        ans %= MOD
print(ans)