結果

問題 No.2494 Sum within Components
ユーザー MottchanMottchan
提出日時 2023-10-06 23:31:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,167 bytes
コンパイル時間 216 ms
コンパイル使用メモリ 10,936 KB
実行使用メモリ 63,392 KB
最終ジャッジ日時 2023-10-06 23:32:04
合計ジャッジ時間 7,173 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
8,860 KB
testcase_01 AC 22 ms
8,792 KB
testcase_02 AC 21 ms
8,860 KB
testcase_03 AC 20 ms
8,916 KB
testcase_04 AC 20 ms
8,888 KB
testcase_05 AC 22 ms
8,800 KB
testcase_06 AC 21 ms
8,768 KB
testcase_07 AC 20 ms
8,832 KB
testcase_08 AC 21 ms
8,884 KB
testcase_09 WA -
testcase_10 AC 88 ms
14,208 KB
testcase_11 WA -
testcase_12 AC 115 ms
14,348 KB
testcase_13 AC 74 ms
12,440 KB
testcase_14 AC 1,331 ms
53,168 KB
testcase_15 AC 1,192 ms
54,452 KB
testcase_16 AC 388 ms
37,172 KB
testcase_17 WA -
testcase_18 AC 545 ms
52,632 KB
testcase_19 AC 1,467 ms
63,392 KB
権限があれば一括ダウンロードができます

ソースコード

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())
if m == 0:
    print(sum(list(map(int,input().split()))))
    exit()
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)
0