結果

問題 No.2494 Sum within Components
ユーザー startcppstartcpp
提出日時 2023-10-06 21:31:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 177 ms / 2,000 ms
コード長 798 bytes
コンパイル時間 1,042 ms
コンパイル使用メモリ 95,032 KB
実行使用メモリ 16,988 KB
最終ジャッジ日時 2023-10-06 21:31:35
合計ジャッジ時間 3,085 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 12 ms
4,376 KB
testcase_10 AC 14 ms
5,036 KB
testcase_11 AC 7 ms
4,644 KB
testcase_12 AC 20 ms
4,580 KB
testcase_13 AC 14 ms
4,684 KB
testcase_14 AC 143 ms
9,660 KB
testcase_15 AC 146 ms
7,604 KB
testcase_16 AC 83 ms
11,556 KB
testcase_17 AC 100 ms
16,976 KB
testcase_18 AC 107 ms
16,988 KB
testcase_19 AC 177 ms
13,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <cassert>
#include <atcoder/dsu>
#include <atcoder/modint>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;
using namespace atcoder;
using mint = modint998244353;

int n, m;
mint a[200000];

signed main() {
	int i;

	cin >> n >> m;
	rep(i, n) { int v; cin >> v; a[i] = v; }

	dsu uf(n);
	rep(i, m) {
		int u, v; cin >> u >> v; u--; v--;
		uf.merge(u, v);
	}

	auto gs = uf.groups();
	mint ans = 1;
	for (auto g: gs) {
		mint s = 0;
		for (int v: g) {
			s += a[v];
		}
		ans *= s.pow(g.size());
	}

	cout << ans.val() << endl;
	return 0;
}
0