結果
| 問題 |
No.2494 Sum within Components
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-10-06 21:45:01 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,047 bytes |
| コンパイル時間 | 1,696 ms |
| コンパイル使用メモリ | 178,644 KB |
| 実行使用メモリ | 15,076 KB |
| 最終ジャッジ日時 | 2024-07-26 15:55:46 |
| 合計ジャッジ時間 | 2,950 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 11 WA * 6 |
ソースコード
#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);
}
}
for(int k=0; k<siz; k++) answer = answer*now %mod;
}
cout << answer << endl;
}