結果
問題 | No.2494 Sum within Components |
ユーザー |
|
提出日時 | 2023-10-06 21:49:46 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 121 ms / 2,000 ms |
コード長 | 1,067 bytes |
コンパイル時間 | 1,889 ms |
コンパイル使用メモリ | 179,540 KB |
実行使用メモリ | 15,000 KB |
最終ジャッジ日時 | 2024-07-26 15:59:44 |
合計ジャッジ時間 | 3,167 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include <bits/stdc++.h>using namespace std;int main(){ios_base::sync_with_stdio(false);cin.tie(nullptr);int N,M; cin >> N >> M;vector<long long> A(N);for(auto &a : A) cin >> a;long long mod = 998244353;vector<vector<long long>> Graph(N);for(int i=0; i<M; i++){int u,v; cin >> u >> v;u--; v--;Graph.at(u).push_back(v);Graph.at(v).push_back(u);}vector<bool> visited(N);long long answer = 1;for(int i=0; i<N; i++){if(visited.at(i)) continue;visited.at(i) = true;long long now = 0,siz = 0;queue<int> Q; Q.push(i);while(Q.size()){int pos = Q.front(); Q.pop();now += A.at(pos); siz++;for(auto to : Graph.at(pos)){if(visited.at(to)) continue;visited.at(to) = true;Q.push(to);}}now %= mod;for(int k=0; k<siz; k++) answer = answer*now %mod;}cout << answer << endl;}