結果

問題 No.2494 Sum within Components
ユーザー MottchanMottchan
提出日時 2023-10-06 23:25:40
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,077 bytes
コンパイル時間 362 ms
コンパイル使用メモリ 87,148 KB
実行使用メモリ 298,240 KB
最終ジャッジ日時 2023-10-06 23:25:50
合計ジャッジ時間 9,781 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
72,036 KB
testcase_01 AC 95 ms
71,464 KB
testcase_02 AC 95 ms
71,620 KB
testcase_03 AC 93 ms
71,700 KB
testcase_04 AC 95 ms
71,736 KB
testcase_05 AC 95 ms
71,736 KB
testcase_06 AC 94 ms
71,708 KB
testcase_07 AC 91 ms
71,460 KB
testcase_08 AC 93 ms
71,636 KB
testcase_09 WA -
testcase_10 TLE -
testcase_11 WA -
testcase_12 AC 792 ms
263,944 KB
testcase_13 AC 674 ms
107,496 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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()
for i in range(n):
    if i in visit:continue
    vi=[False]*n
    road_s = set()
    road_l = []
    dfs(i,vi)
    visit |= road_s
    aa=0
    for j in list(road_s):
        aa += l[j]
    if aa:
        ans *= aa ** len(road_s)
        ans %= MOD

print(ans)
0