結果

問題 No.2494 Sum within Components
ユーザー MottchanMottchan
提出日時 2023-10-06 23:15:32
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 991 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 87,344 KB
実行使用メモリ 91,740 KB
最終ジャッジ日時 2023-10-06 23:15:39
合計ジャッジ時間 6,110 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
76,264 KB
testcase_01 AC 95 ms
71,800 KB
testcase_02 AC 108 ms
71,812 KB
testcase_03 AC 96 ms
71,988 KB
testcase_04 AC 103 ms
76,580 KB
testcase_05 AC 96 ms
71,732 KB
testcase_06 AC 95 ms
71,408 KB
testcase_07 AC 796 ms
78,516 KB
testcase_08 AC 96 ms
71,636 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
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.add(crr)
    for nxt in graph[crr]:
        if v[nxt]:continue
        dfs(nxt, v)
    v[crr] = False
    #road.pop(crr)

vi=[False]*n
ans=1
for i in range(n):
    if vi[i]:continue
    road = set()
    dfs(i,vi)
    aa=0
    #print(road)
    for j in list(road):
        aa += l[j]
    if aa:
        ans *= aa
        ans %= MOD

print(ans)
0