結果

問題 No.2494 Sum within Components
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2023-10-06 22:19:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 457 ms / 2,000 ms
コード長 600 bytes
コンパイル時間 342 ms
コンパイル使用メモリ 87,120 KB
実行使用メモリ 110,608 KB
最終ジャッジ日時 2023-10-06 22:19:29
合計ジャッジ時間 5,019 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,684 KB
testcase_01 AC 72 ms
71,384 KB
testcase_02 AC 72 ms
71,420 KB
testcase_03 AC 72 ms
71,300 KB
testcase_04 AC 72 ms
71,288 KB
testcase_05 AC 74 ms
71,328 KB
testcase_06 AC 72 ms
71,428 KB
testcase_07 AC 73 ms
71,428 KB
testcase_08 AC 72 ms
71,364 KB
testcase_09 AC 129 ms
78,812 KB
testcase_10 AC 145 ms
81,556 KB
testcase_11 AC 128 ms
79,532 KB
testcase_12 AC 156 ms
81,116 KB
testcase_13 AC 142 ms
80,600 KB
testcase_14 AC 404 ms
102,268 KB
testcase_15 AC 419 ms
95,052 KB
testcase_16 AC 237 ms
100,292 KB
testcase_17 AC 141 ms
103,620 KB
testcase_18 AC 216 ms
109,752 KB
testcase_19 AC 457 ms
110,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m = map(int,input().split())
A = list(map(int,input().split()))

ans = 1
mod = 998244353

e = [[] for i in range(n)]
for _ in range(m):
    u,v = [int(x)-1 for x in input().split()]
    e[u].append(v)
    e[v].append(u)

vis = [0]*n

for i in range(n):
    if vis[i]:
        continue
    nums = 0
    q = [i]
    vis[i] = 1
    size = 0
    while q:
        now = q.pop()
        nums += A[now]
        size += 1
        for nex in e[now]:
            if vis[nex]:
                continue
            vis[nex] = 1
            q.append(nex)

    ans *= pow(nums,size,mod)
    ans %= mod
print(ans)
0