結果
| 問題 |
No.2494 Sum within Components
|
| コンテスト | |
| ユーザー |
Koi
|
| 提出日時 | 2023-10-06 21:45:54 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 460 ms / 2,000 ms |
| コード長 | 657 bytes |
| コンパイル時間 | 530 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 129,052 KB |
| 最終ジャッジ日時 | 2024-07-26 15:56:27 |
| 合計ジャッジ時間 | 4,082 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
from collections import defaultdict,deque
Mod=998244353
N,M=map(int,input().split())
A=list(map(int,input().split()))
G=defaultdict(list)
for i in range(M):
u,v=map(int,input().split())
G[u].append(v)
G[v].append(u)
C=[0]*(N+1)
color_sum=[0]*(N+1)
T=1
c=1
while T<=N:
que=deque([T])
C[T]=c
while len(que):
p=que.popleft()
for q in G[p]:
if(C[q]==0):
C[q]=C[p]
que.append(q)
while T<=N and C[T]!=0:
T+=1
c+=1
for i in range(1,N+1):
color_sum[C[i]]+=A[i-1]
ans=1
# print(color_sum,C)
for i in range(1,N+1):
ans*=color_sum[C[i]]
ans%=Mod
print(ans)
Koi