結果

問題 No.2494 Sum within Components
ユーザー Nzt3Nzt3
提出日時 2023-10-07 15:08:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 839 bytes
コンパイル時間 2,171 ms
コンパイル使用メモリ 207,800 KB
実行使用メモリ 13,544 KB
最終ジャッジ日時 2023-10-07 15:09:05
合計ジャッジ時間 4,230 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 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 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 6 ms
4,380 KB
testcase_10 AC 8 ms
4,376 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 11 ms
4,376 KB
testcase_13 AC 7 ms
4,384 KB
testcase_14 AC 79 ms
10,964 KB
testcase_15 AC 80 ms
9,652 KB
testcase_16 AC 36 ms
8,324 KB
testcase_17 AC 36 ms
8,532 KB
testcase_18 AC 41 ms
8,992 KB
testcase_19 AC 106 ms
13,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int const mod=998244353;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,M;
  cin>>N>>M;
  vector A(N,0);
  for(int &i:A)cin>>i;
  vector G(N,vector(0,0));
  for(int i=0;i<M;i++){
    int U,V;
    cin>>U>>V;
    --U,--V;
    G[U].push_back(V);
    G[V].push_back(U);
  }
  vector vst(N,false);
  ll ans=1;
  for(int i=0;i<N;i++){
    if(vst[i])continue;
    int cnt=1;
    ll now=A[i];
    queue<int> bfs;
    bfs.push(i);
    vst[i]=1;
    while(bfs.size()){
      int v=bfs.front();
      bfs.pop();
      for(int j:G[v]){
        if(!vst[j]){
          cnt+=1;
          now+=A[j];
          bfs.push(j);
          vst[j]=1;
        }
      }
    }
    now%=mod;
    while(cnt>0){
      cnt-=1;
      ans=ans*now%mod;
    }
  }
  cout<<ans<<'\n';
}
0