結果

問題 No.2494 Sum within Components
ユーザー minimumminimum
提出日時 2023-10-06 21:32:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 462 ms / 2,000 ms
コード長 699 bytes
コンパイル時間 382 ms
コンパイル使用メモリ 87,196 KB
実行使用メモリ 118,980 KB
最終ジャッジ日時 2023-10-06 21:32:21
合計ジャッジ時間 5,517 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
71,732 KB
testcase_01 AC 90 ms
71,780 KB
testcase_02 AC 94 ms
71,812 KB
testcase_03 AC 94 ms
71,608 KB
testcase_04 AC 93 ms
71,900 KB
testcase_05 AC 98 ms
71,784 KB
testcase_06 AC 92 ms
71,896 KB
testcase_07 AC 94 ms
71,460 KB
testcase_08 AC 93 ms
71,836 KB
testcase_09 AC 150 ms
79,544 KB
testcase_10 AC 173 ms
81,572 KB
testcase_11 AC 150 ms
79,968 KB
testcase_12 AC 172 ms
81,352 KB
testcase_13 AC 157 ms
80,488 KB
testcase_14 AC 438 ms
105,012 KB
testcase_15 AC 427 ms
97,672 KB
testcase_16 AC 267 ms
103,020 KB
testcase_17 AC 198 ms
118,980 KB
testcase_18 AC 259 ms
117,400 KB
testcase_19 AC 462 ms
117,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque


MOD = 998244353
N, M = map(int, input().split())
A = list(map(int, input().split()))
edges = [[] for i in range(N)]
for i in range(M):
    u, v = map(lambda x: x - 1, map(int, input().split()))
    edges[u].append(v)
    edges[v].append(u)

ans = 1
done = [0] * N
for i in range(N):
    if done[i]:
        continue
    done[i] = 1
    dq = deque([i])
    c = 1
    s = A[i]
    while dq:
        now = dq.popleft()
        for nxt in edges[now]:
            if done[nxt]:
                continue
            done[nxt] = 1
            dq.append(nxt)
            c += 1
            s += A[nxt]
            s %= MOD
    ans *= pow(s, c, MOD)
    ans %= MOD

print(ans)
0