結果

問題 No.2494 Sum within Components
ユーザー Akijin_007Akijin_007
提出日時 2023-10-06 22:27:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 415 ms / 2,000 ms
コード長 738 bytes
コンパイル時間 507 ms
コンパイル使用メモリ 87,272 KB
実行使用メモリ 110,632 KB
最終ジャッジ日時 2023-10-06 22:27:10
合計ジャッジ時間 5,065 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,588 KB
testcase_01 AC 69 ms
71,596 KB
testcase_02 AC 70 ms
71,420 KB
testcase_03 AC 77 ms
71,304 KB
testcase_04 AC 70 ms
71,152 KB
testcase_05 AC 71 ms
71,400 KB
testcase_06 AC 70 ms
71,152 KB
testcase_07 AC 69 ms
71,420 KB
testcase_08 AC 69 ms
71,600 KB
testcase_09 AC 118 ms
78,284 KB
testcase_10 AC 130 ms
79,704 KB
testcase_11 AC 122 ms
78,552 KB
testcase_12 AC 142 ms
80,628 KB
testcase_13 AC 159 ms
78,920 KB
testcase_14 AC 371 ms
102,136 KB
testcase_15 AC 370 ms
96,004 KB
testcase_16 AC 216 ms
101,892 KB
testcase_17 AC 131 ms
103,584 KB
testcase_18 AC 213 ms
110,088 KB
testcase_19 AC 415 ms
110,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#int(input())
#map(int, input().split())
#list(map(int, input().split()))

import sys
sys.setrecursionlimit(200000)


N, M = map(int, input().split())
A = list(map(int, input().split()))

to = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    to[a-1].append(b-1)
    to[b-1].append(a-1)

mod = 998244353

# p = [0] * N
v = [0] * N
ans = 1
for i in range(N):
    if v[i] != 0:
        continue
    q = [i]
    v[i] = 1
    s = A[i]
    c = 1
    while q:
        t = q.pop()
        for y in to[t]:
            if v[y] == 0:
                q.append(y)
                v[y] = 1
                s += A[y]
                s %= mod
                c += 1

    ans = (ans * pow(s, c, mod)) % mod


print(ans)

0