結果
問題 |
No.2494 Sum within Components
|
ユーザー |
|
提出日時 | 2025-03-28 00:34:59 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 69 ms / 2,000 ms |
コード長 | 820 bytes |
コンパイル時間 | 3,676 ms |
コンパイル使用メモリ | 286,236 KB |
実行使用メモリ | 18,036 KB |
最終ジャッジ日時 | 2025-03-28 00:35:05 |
合計ジャッジ時間 | 5,948 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i) #define all(a) (a).begin(),(a).end() #include <atcoder/modint> #include <atcoder/dsu> using namespace atcoder; using mint = modint998244353; int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int N, M; cin >> N >> M; vector<ll> A(N); rep(i, 0, N) cin >> A[i]; dsu uf(N); rep(i, 0, M) { int U, V; cin >> U >> V; --U, --V; uf.merge(U, V); } mint ans = 1; vector<vector<int>> group = uf.groups(); rep(i, 0, group.size()) { mint t = 0; rep(j, 0, group[i].size()) t += A[group[i][j]]; ans *= t.pow(group[i].size()); } cout << ans.val() << '\n'; }