結果
問題 | No.2494 Sum within Components |
ユーザー | 沙耶花 |
提出日時 | 2023-10-06 21:28:17 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 192 ms / 2,000 ms |
コード長 | 586 bytes |
コンパイル時間 | 4,651 ms |
コンパイル使用メモリ | 264,016 KB |
実行使用メモリ | 18,048 KB |
最終ジャッジ日時 | 2024-07-26 15:43:57 |
合計ジャッジ時間 | 6,540 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include <stdio.h> #include <atcoder/all> #include <bits/stdc++.h> using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 1000000000000000001 int main(){ int n,m; cin>>n>>m; vector<long long> a(n); rep(i,n)cin>>a[i]; dsu D(n); rep(i,m){ int u,v; cin>>u>>v; u--,v--; D.merge(u,v); } auto g = D.groups(); mint ans = 1; rep(i,g.size()){ mint t = 0; rep(j,g[i].size())t += a[g[i][j]]; ans *= t.pow(g[i].size()); } cout<<ans.val()<<endl; return 0; }