結果

問題 No.2494 Sum within Components
ユーザー ronpooronpoo
提出日時 2023-10-27 16:10:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 955 ms / 2,000 ms
コード長 756 bytes
コンパイル時間 365 ms
コンパイル使用メモリ 81,856 KB
実行使用メモリ 178,728 KB
最終ジャッジ日時 2023-10-27 16:10:22
合計ジャッジ時間 6,561 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,576 KB
testcase_01 AC 36 ms
53,576 KB
testcase_02 AC 36 ms
53,576 KB
testcase_03 AC 36 ms
53,576 KB
testcase_04 AC 36 ms
53,576 KB
testcase_05 AC 36 ms
53,576 KB
testcase_06 AC 36 ms
53,576 KB
testcase_07 AC 36 ms
53,576 KB
testcase_08 AC 36 ms
53,576 KB
testcase_09 AC 112 ms
83,316 KB
testcase_10 AC 122 ms
79,964 KB
testcase_11 AC 89 ms
77,436 KB
testcase_12 AC 139 ms
84,420 KB
testcase_13 AC 124 ms
80,512 KB
testcase_14 AC 842 ms
161,296 KB
testcase_15 AC 789 ms
166,916 KB
testcase_16 AC 204 ms
99,612 KB
testcase_17 AC 141 ms
125,580 KB
testcase_18 AC 189 ms
115,996 KB
testcase_19 AC 955 ms
178,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)

N, M = map(int, input().split())
A = list(map(int, input().split()))
UV = [list(map(int, input().split())) for _ in range(M)]
MOD = 998244353

G = [[] for _ in range(N)]
for i in range(M):
    u, v = UV[i]
    u -= 1
    v -= 1
    G[u].append(v)
    G[v].append(u)
    
link = [-1] * N

def dfs(now):
    for nxt in G[now]:
        if link[now] == link[nxt]:
            continue
        link[nxt] = link[now]
        dfs(nxt)

cnt = 0
for i in range(N):
    if link[i] != -1:
        continue
    cnt += 1
    link[i] = cnt
    dfs(i)

a = [[0] * 2 for _ in range(cnt)]
for i in range(N):
    a[link[i]-1][0] += A[i]
    a[link[i]-1][1] += 1
    
ans = 1
for x, y in a:
    ans *= x ** y
    ans %= MOD
print(ans)
0