結果
問題 | No.2494 Sum within Components |
ユーザー |
|
提出日時 | 2023-10-06 21:34:44 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 184 ms / 2,000 ms |
コード長 | 491 bytes |
コンパイル時間 | 3,090 ms |
コンパイル使用メモリ | 256,604 KB |
実行使用メモリ | 17,448 KB |
最終ジャッジ日時 | 2024-07-26 15:49:58 |
合計ジャッジ時間 | 4,948 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include <bits/stdc++.h>#include <atcoder/modint>#include <atcoder/dsu>using namespace std;using namespace atcoder;using mint = modint998244353;int main() {int n, m;cin >> n >> m;vector<int> a(n);for (int i = 0; i < n; i++) cin >> a[i];dsu uf(n);while (m--) {int u, v;cin >> u >> v;u--; v--;uf.merge(u, v);}mint ans = 1;for (auto i: uf.groups()) {mint k = 0;for (int j: i) k += a[j];ans *= mint(k).pow(i.size());}cout << ans.val() << '\n';}