結果

問題 No.2494 Sum within Components
ユーザー askr58askr58
提出日時 2023-10-06 21:48:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 237 ms / 2,000 ms
コード長 1,068 bytes
コンパイル時間 4,526 ms
コンパイル使用メモリ 265,152 KB
実行使用メモリ 22,008 KB
最終ジャッジ日時 2023-10-06 21:48:29
合計ジャッジ時間 6,671 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 13 ms
4,376 KB
testcase_10 AC 16 ms
4,860 KB
testcase_11 AC 6 ms
4,376 KB
testcase_12 AC 23 ms
4,816 KB
testcase_13 AC 15 ms
4,396 KB
testcase_14 AC 210 ms
15,100 KB
testcase_15 AC 209 ms
13,616 KB
testcase_16 AC 97 ms
14,136 KB
testcase_17 AC 101 ms
21,392 KB
testcase_18 AC 113 ms
22,008 KB
testcase_19 AC 237 ms
18,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
using mint=modint998244353;

int main()
{
    int n,m;
    cin>>n>>m;
    vector<mint> a(n);
    for(int i=0;i<n;i++){
        int t;
        cin>>t;
        a[i]=t;
    }
    vector<vector<int>> graph(n);
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        u--;v--;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    vector<mint> sum;
    vector<vector<int>> hist;
    vector<bool> seen(n);
    function<void(int,int)> rec=[&](int i,int t)->void{
        seen[i]=true;
        sum[t]+=a[i];
        hist[t].push_back(i);
        for(int x:graph[i]){
            if(!seen[x])rec(x,t);
        }

    };
    int cnt=0;
    for(int i=0;i<n;i++){
        if(seen[i])continue;
        cnt++;
        sum.push_back(0);
        hist.push_back(vector<int>());
        rec(i,cnt-1);
    }

    mint ans=1;
    for(int i=0;i<cnt;i++){
        for(int j=0;j<hist[i].size();j++)ans*=sum[i];
    }
    cout<<ans.val()<<endl;
}
0