結果
| 問題 |
No.2494 Sum within Components
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-10-06 23:49:24 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 235 ms / 2,000 ms |
| コード長 | 1,180 bytes |
| コンパイル時間 | 5,400 ms |
| コンパイル使用メモリ | 309,348 KB |
| 実行使用メモリ | 17,612 KB |
| 最終ジャッジ日時 | 2024-07-26 17:23:15 |
| 合計ジャッジ時間 | 7,063 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
typedef long long ll;
typedef unsigned long long ull;
const int MAX = 1e9;
const int MIN = -1*1e9;
const ll MAXLL = 1e18;
const ll MINLL = -1*1e18;
//const ll MOD = 998244353;
//const ll MOD = 1000000007;
vector<vector<int>> G(200010);
vector<bool> F(200010);
vector<int> Path;
void DFS(int N)
{
Path.push_back(N);
F[N] = true;
for(auto x : G[N])
{
if(!F[x]) DFS(x);
}
return;
}
int main()
{
int N,M; cin >> N >> M;
vector<ll> V(N+1);
for(int i = 1; i <= N; i++)
{
cin >> V[i];
}
for(int i = 0; i < M; i++)
{
int A,B; cin >> A >> B;
G[A].push_back(B);
G[B].push_back(A);
}
mint Ans = 1;
for(int i = 1; i <= N; i++)
{
if(!F[i])
{
Path.clear();
DFS(i);
ll Count = 0;
for(auto x : Path)
{
Count += V[x];
}
for(int j = 0; j < Path.size(); j++) Ans *= Count;
}
}
cout << Ans.val() << endl;
return 0;
}