結果

問題 No.2494 Sum within Components
ユーザー GOTKAKOGOTKAKO
提出日時 2023-10-06 21:45:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,047 bytes
コンパイル時間 1,680 ms
コンパイル使用メモリ 176,760 KB
実行使用メモリ 15,132 KB
最終ジャッジ日時 2023-10-06 21:45:05
合計ジャッジ時間 3,268 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 7 ms
4,376 KB
testcase_10 AC 8 ms
4,380 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 39 ms
9,328 KB
testcase_18 AC 45 ms
9,756 KB
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0