結果

問題 No.2494 Sum within Components
ユーザー VvyLw
提出日時 2023-10-07 00:03:38
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 553 bytes
コンパイル時間 1,434 ms
コンパイル使用メモリ 112,428 KB
実行使用メモリ 17,176 KB
最終ジャッジ日時 2024-07-26 17:29:07
合計ジャッジ時間 2,645 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <atcoder/dsu>
#include <atcoder/modint>
typedef atcoder::modint998244353 mint;
int main() {
	std::cin.tie(nullptr) -> sync_with_stdio(false);
	int n, m;
	std::cin >> n >> m;
	std::vector<int> a(n);
	for(auto &el: a) std::cin >> el;
	atcoder::dsu uf(n);
	while(m--) {
		int u, v;
		std::cin >> u >> v;
		uf.merge(--u, --v);
	}
	mint ans = 1;
	for(const auto g: uf.groups()) {
		mint res = 0;
		for(const auto i: g) {
			res += a[i];
		}
		ans *= res.pow(std::ssize(g));
	}
	std::cout << ans.val() << '\n';
}
0