結果
| 問題 |
No.2494 Sum within Components
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-06 13:41:38 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 227 ms / 2,000 ms |
| コード長 | 591 bytes |
| コンパイル時間 | 4,550 ms |
| コンパイル使用メモリ | 254,224 KB |
| 最終ジャッジ日時 | 2025-02-20 22:32:49 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using mint = modint998244353;
int N, M;
ll A[202020];
vector<int> G[202020];
int main() {
cin >> N >> M;
for (int i = 0; i < N; i++) cin >> A[i];
dsu uf(N);
for (int i = 0; i < M; i++) {
int u, v; cin >> u >> v;
u--, v--;
uf.merge(u, v);
}
mint ans = 1;
for (auto s: uf.groups()) {
mint sum = 0;
for (auto x: s) {
sum += A[x];
}
ans *= sum.pow(s.size());
}
cout << ans.val() << endl;
return 0;
}