結果

問題 No.2494 Sum within Components
コンテスト
ユーザー vjudge1
提出日時 2025-11-20 17:15:09
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,151 bytes
コンパイル時間 3,578 ms
コンパイル使用メモリ 322,268 KB
実行使用メモリ 16,512 KB
最終ジャッジ日時 2025-11-20 17:15:15
合計ジャッジ時間 5,625 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 11 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long 
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, ans = 1ll;
    cin >> n >> m;

    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++;
            }
        }

        int prod = 1ll;
        while(cnt) {
            prod = (prod * sum) % mod2;
            cnt--;
        }
        ans = (ans * prod) % mod2;
    }
    cout << ans % mod2;
}
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;
}
0