結果

問題 No.2494 Sum within Components
ユーザー yelyel
提出日時 2023-10-06 23:49:24
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 232 ms / 2,000 ms
コード長 1,180 bytes
コンパイル時間 5,541 ms
コンパイル使用メモリ 307,352 KB
実行使用メモリ 17,564 KB
最終ジャッジ日時 2023-10-06 23:49:32
合計ジャッジ時間 7,760 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,560 KB
testcase_01 AC 3 ms
7,716 KB
testcase_02 AC 5 ms
7,852 KB
testcase_03 AC 4 ms
7,552 KB
testcase_04 AC 5 ms
7,652 KB
testcase_05 AC 4 ms
7,796 KB
testcase_06 AC 4 ms
7,596 KB
testcase_07 AC 5 ms
7,784 KB
testcase_08 AC 4 ms
7,616 KB
testcase_09 AC 15 ms
8,584 KB
testcase_10 AC 16 ms
8,548 KB
testcase_11 AC 8 ms
8,040 KB
testcase_12 AC 24 ms
9,160 KB
testcase_13 AC 16 ms
8,640 KB
testcase_14 AC 204 ms
16,952 KB
testcase_15 AC 208 ms
17,564 KB
testcase_16 AC 84 ms
10,460 KB
testcase_17 AC 83 ms
9,304 KB
testcase_18 AC 94 ms
9,956 KB
testcase_19 AC 232 ms
16,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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