結果
問題 | No.2494 Sum within Components |
ユーザー |
|
提出日時 | 2023-10-06 21:27:34 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 73 ms / 2,000 ms |
コード長 | 514 bytes |
コンパイル時間 | 986 ms |
コンパイル使用メモリ | 80,228 KB |
実行使用メモリ | 17,280 KB |
最終ジャッジ日時 | 2024-07-26 15:42:55 |
合計ジャッジ時間 | 2,123 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include<iostream>#include<cassert>#include<atcoder/dsu>using namespace std;int N,M;int A[2<<17];const int mod=998244353;int ans[2<<17];int main(){ios::sync_with_stdio(false);cin.tie(nullptr);cin>>N>>M;for(int i=0;i<N;i++)cin>>A[i];atcoder::dsu uf(N);for(;M--;){int u,v;cin>>u>>v;u--,v--;uf.merge(u,v);}long long t=1;for(vector<int>g:uf.groups()){int now=0;for(int u:g){now+=A[u];if(now>=mod)now-=mod;}for(int u:g)t=t*now%mod;}cout<<t<<endl;}