結果
| 問題 |
No.2494 Sum within Components
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-10-07 15:08:59 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 91 ms / 2,000 ms |
| コード長 | 839 bytes |
| コンパイル時間 | 2,080 ms |
| コンパイル使用メモリ | 203,760 KB |
| 最終ジャッジ日時 | 2025-02-17 06:07:46 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int const mod=998244353;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N,M;
cin>>N>>M;
vector A(N,0);
for(int &i:A)cin>>i;
vector G(N,vector(0,0));
for(int i=0;i<M;i++){
int U,V;
cin>>U>>V;
--U,--V;
G[U].push_back(V);
G[V].push_back(U);
}
vector vst(N,false);
ll ans=1;
for(int i=0;i<N;i++){
if(vst[i])continue;
int cnt=1;
ll now=A[i];
queue<int> bfs;
bfs.push(i);
vst[i]=1;
while(bfs.size()){
int v=bfs.front();
bfs.pop();
for(int j:G[v]){
if(!vst[j]){
cnt+=1;
now+=A[j];
bfs.push(j);
vst[j]=1;
}
}
}
now%=mod;
while(cnt>0){
cnt-=1;
ans=ans*now%mod;
}
}
cout<<ans<<'\n';
}