結果
問題 | No.2494 Sum within Components |
ユーザー |
![]() |
提出日時 | 2023-10-06 21:28:17 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 197 ms / 2,000 ms |
コード長 | 586 bytes |
コンパイル時間 | 3,930 ms |
コンパイル使用メモリ | 253,868 KB |
最終ジャッジ日時 | 2025-02-17 04:47:55 |
ジャッジサーバーID (参考情報) |
judge4 / 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 1000000000000000001int 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;}