結果

問題 No.2494 Sum within Components
ユーザー RustiebeatsRustiebeats
提出日時 2023-10-06 21:30:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,505 bytes
コンパイル時間 1,502 ms
コンパイル使用メモリ 168,020 KB
実行使用メモリ 6,264 KB
最終ジャッジ日時 2023-10-06 21:30:37
合計ジャッジ時間 2,874 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 5 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 27 ms
6,228 KB
testcase_18 AC 28 ms
6,200 KB
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _DEBU123G
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fi first
#define se second
#define all(x) (x).begin(),(x).end() 
#define sz(x) (x).size()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<int> vi;
typedef vector<pii> vii;
const long double pi = acos(-1.0);
const int INF = 987654321;
const ll LLINF = 4e18;
const double eps = 1e-9;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
///

int parent[200004];
ll sizee[200004];

const ll MOD = 998244353;
int find(int n){
    if(n==parent[n]) return n;
    return parent[n] = find(parent[n]);
}
void merge(int u, int v){
    u=find(u);
    v=find(v);
    if(u==v) return;
    parent[v] = u;
    sizee[u] += sizee[v];
}


int main(){
#ifdef _DEBUG   
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif      
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N, M; cin >> N >> M;
    vector<int> V(N); for(auto &v: V) cin >> v;
    for(int i = 1; i <= N; i++){
        parent[i] = i;
        sizee[i] = V[i-1];
    }
    while(M--){
        int u, v; cin >> u >> v;
        merge(u, v);
    }
    ll ans = 1;
    for(int i = 1; i <= N; i++){
        ans *= sizee[find(i)];
        ans %= MOD;
    }
    cout << ans << endl;
    
    return 0;
}
0