結果

問題 No.2494 Sum within Components
ユーザー june19312june19312
提出日時 2023-10-06 22:05:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 526 ms / 2,000 ms
コード長 1,524 bytes
コンパイル時間 364 ms
コンパイル使用メモリ 87,248 KB
実行使用メモリ 150,996 KB
最終ジャッジ日時 2023-10-06 22:05:55
合計ジャッジ時間 5,675 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
71,896 KB
testcase_01 AC 92 ms
71,876 KB
testcase_02 AC 94 ms
71,620 KB
testcase_03 AC 91 ms
71,740 KB
testcase_04 AC 92 ms
71,768 KB
testcase_05 AC 92 ms
71,780 KB
testcase_06 AC 93 ms
71,640 KB
testcase_07 AC 93 ms
71,640 KB
testcase_08 AC 92 ms
71,456 KB
testcase_09 AC 152 ms
79,760 KB
testcase_10 AC 171 ms
82,544 KB
testcase_11 AC 161 ms
79,900 KB
testcase_12 AC 178 ms
83,056 KB
testcase_13 AC 174 ms
81,636 KB
testcase_14 AC 472 ms
103,136 KB
testcase_15 AC 451 ms
101,416 KB
testcase_16 AC 315 ms
106,568 KB
testcase_17 AC 244 ms
150,996 KB
testcase_18 AC 311 ms
133,016 KB
testcase_19 AC 526 ms
125,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M = map(int,input().split())
A = [-1] + list(map(int,input().split()))
mod = 998244353

G = []
for i in range(N+1):
    G.append([])

for i in range(M):
    U,V = map(int,input().split())
    G[U].append(V)
    G[V].append(U)

from collections import deque

def renketu_seibunsuu():
    number_of_renketu = 0 #連結成分数
    number_of_visited = 0 #訪問済み頂点
    renketu_dict = {} #最後に関数が返す辞書

    visited = [False]*(N+1)

    edge = 0
    for ii in range(10_000_000): #連結成分数が1000万を超えそうなときは要調整
        QQ = deque()
        renketu_dict[ii] = []

        for i in range(edge+1,len(visited)):
            if i == 0:
                continue
            if visited[i] == False:
                QQ.append(i)
                visited[i] = True
                number_of_visited+=1
                renketu_dict[ii].append(i)
                edge = i
                break

        while len(QQ)>0:
            tmp = QQ.popleft()
            for j in G[tmp]:
                if visited[j] == False:
                    visited[j] = True
                    QQ.append(j)
                    number_of_visited+=1
                    renketu_dict[ii].append(j)

        if number_of_visited >= N:
            break
    
    return renketu_dict

ren_seibun = renketu_seibunsuu()

ans = 1
for ind,nex in ren_seibun.items():
    tmp = 0
    for ii,vv in enumerate(nex):
        tmp += A[vv]
    
    ans *= pow(tmp,len(nex),mod)
    ans %= mod

print(ans%mod)

    
0