結果
| 問題 |
No.2494 Sum within Components
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-11-20 17:08:59 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,187 bytes |
| コンパイル時間 | 3,348 ms |
| コンパイル使用メモリ | 320,076 KB |
| 実行使用メモリ | 14,208 KB |
| 最終ジャッジ日時 | 2025-11-20 17:09:04 |
| 合計ジャッジ時間 | 4,874 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 11 WA * 6 |
ソースコード
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ld long double
#define nl cout << "\n";
#define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());}
#define forn(a, b) for (int i = a; i < b; i++)
#define __builtin_popcountll __builtin_popcountll
#define __builtin_clzll __builtin_clzll
#define __builtin_ctzll __builtin_ctzll
#define yesno(b) cout << ((b)? "YES" : "NO");
#define pii pair<int, int>
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define all(a) a.begin(), a.end()
#define vi vector<int>
#define hhh cout << "here" << endl;
#define mod1 1000000007
#define mod2 998244353ll
void solve()
{
int n, m;
cin >> n >> m;
long long ans = 1ll;
vector<int> adj[n + 1];
vector<int> v(n + 1);
for(int i = 1 ; i <= n ; i++) cin >> v[i];
for(int i = 0 ; i < m ; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
vector<int> vis(n + 1, 0);
for(int i = 1 ; i <= n ; i++) {
if(vis[i]) continue;
queue<int> q;
long long sum = 0, cnt = 0;
q.push(i);
vis[i] = 1;
sum += v[i], cnt = 1;
while(!q.empty()) {
int x = q.front(); q.pop();
for(int y : adj[x]) {
if(vis[y]) continue;
vis[y] = 1;
q.push(y);
sum += v[y];
cnt++;
}
}
// cout << sum << " " << cnt << endl;
long long prod = 1ll;
while(cnt) {
prod = (prod * sum) % mod2;
cnt--;
}
ans = (ans * prod) % mod2;
}
cout << ans;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int t = 1;
// cin >> t;
while (t--)
{
solve();
nl;
}
return 0;
}
vjudge1