結果
| 問題 |
No.2494 Sum within Components
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-09-01 10:36:54 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 126 ms / 2,000 ms |
| コード長 | 1,155 bytes |
| コンパイル時間 | 4,655 ms |
| コンパイル使用メモリ | 255,608 KB |
| 最終ジャッジ日時 | 2025-02-16 15:58:16 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
struct Fast {
Fast() {
std::cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << setprecision(10);
}
} fast;
#define rep(i, a, b) for (int(i) = (a); (i) < (int)(b); (i)++)
using mint = modint998244353;
int main() {
int n, m;
cin >> n >> m;
vector<int> a(n);
rep(i, 0, n) cin >> a[i];
vector<vector<int>> g(n, vector<int>());
rep(i, 0, m) {
int u, v;
cin >> u >> v;
u--;
v--;
g[u].push_back(v);
g[v].push_back(u);
}
vector<bool> seen(n, false);
vector<int> root(n, -1), size(n, 0);
vector<mint> sum(n, 0);
stack<int> st;
rep(i, 0, n) st.push(i);
while (!st.empty()) {
int x = st.top();
st.pop();
if (seen[x]) continue;
seen[x] = true;
if (root[x] == -1) root[x] = x;
sum[root[x]] += a[x];
size[root[x]]++;
for (auto y : g[x]) {
if (root[y] != -1) continue;
root[y] = root[x];
st.push(y);
}
}
mint ans = 1;
rep(i, 0, n) {
if (root[i] != i) continue;
rep(j, 0, size[i]) ans *= sum[i];
}
cout << ans.val() << endl;
}