結果

問題 No.2494 Sum within Components
ユーザー VvyLwVvyLw
提出日時 2023-10-07 00:03:38
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 553 bytes
コンパイル時間 1,358 ms
コンパイル使用メモリ 111,988 KB
実行使用メモリ 17,404 KB
最終ジャッジ日時 2023-10-07 00:03:41
合計ジャッジ時間 3,058 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 7 ms
4,380 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 8 ms
4,380 KB
testcase_13 AC 6 ms
4,380 KB
testcase_14 AC 53 ms
9,188 KB
testcase_15 AC 52 ms
7,224 KB
testcase_16 AC 38 ms
11,176 KB
testcase_17 AC 49 ms
17,404 KB
testcase_18 AC 52 ms
16,768 KB
testcase_19 AC 74 ms
13,236 KB
権限があれば一括ダウンロードができます

ソースコード

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