結果
問題 | No.2494 Sum within Components |
ユーザー |
|
提出日時 | 2023-10-06 21:53:07 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 92 ms / 2,000 ms |
コード長 | 850 bytes |
コンパイル時間 | 2,785 ms |
コンパイル使用メモリ | 252,044 KB |
実行使用メモリ | 17,152 KB |
最終ジャッジ日時 | 2024-07-26 16:02:12 |
合計ジャッジ時間 | 4,324 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll=long long; const ll md=998244353; vector<ll>adj[202020]; ll pw(ll a,ll b) { ll c=1; while(b>0) { if(b&1)c=c*a%md; a=a*a%md; b>>=1; } return c; } int main() { cin.tie(0)->sync_with_stdio(0); ll n,m;cin>>n>>m; vector<ll>vec(n);for(ll&i:vec)cin>>i; for(int i=0;i<m;i++) { ll u,v;cin>>u>>v; u--;v--; adj[u].push_back(v); adj[v].push_back(u); } vector<ll>vis(n); auto dfs=[&](auto dfs,ll v,ll&val,ll&sz)->void { if(vis[v])return; val=(val+vec[v])%md;sz++;vis[v]=1; for(ll u:adj[v])dfs(dfs,u,val,sz); }; ll ans=1; for(int i=0;i<n;i++) { ll val=0,sz=0; dfs(dfs,i,val,sz); if(sz>0)ans=ans*pw(val,sz)%md; } cout<<ans; }