結果

問題 No.2494 Sum within Components
ユーザー myaumyau
提出日時 2023-10-06 21:35:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 169 ms / 2,000 ms
コード長 1,643 bytes
コンパイル時間 4,645 ms
コンパイル使用メモリ 263,732 KB
実行使用メモリ 7,176 KB
最終ジャッジ日時 2023-10-06 21:35:49
合計ジャッジ時間 6,087 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 11 ms
4,380 KB
testcase_10 AC 12 ms
4,376 KB
testcase_11 AC 5 ms
4,380 KB
testcase_12 AC 19 ms
4,376 KB
testcase_13 AC 12 ms
4,380 KB
testcase_14 AC 142 ms
5,668 KB
testcase_15 AC 146 ms
4,924 KB
testcase_16 AC 71 ms
5,416 KB
testcase_17 AC 82 ms
7,176 KB
testcase_18 AC 88 ms
7,040 KB
testcase_19 AC 169 ms
7,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

//only for atcoder
#include<atcoder/all>
using namespace atcoder;

#define rep(i,l,r) for(ll i=(l); i<(r); i++)
#define rrep(i,l,r) for(ll i=(r)-1; i>=(l); i--)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define REV(c) reverse(ALL(c))
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MINV(c) *min_element(ALL(c))
#define MAXV(c) *max_element(ALL(c))

template <typename TYPE>
void print(TYPE vec){
  rep(i,0,vec.size()){
    cout << vec[i];
    if(i == vec.size()-1){
      cout << endl;
    }
    else{
      cout << " ";
    }
  }
}

using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VS = vector<string>;
using VVS = vector<VS>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VC = vector<char>;
using VVC = vector<VC>;
using VD = vector<ld>;
using VVD = vector<VD>;
using P = pair<ll,ll>;
using VP = vector<P>;
using VVP = vector<VP>;
const ll LINF = 2e18;
const int INF = 2e9;
using mint = modint998244353;

int main(){
  int N, M;
  cin >> N >> M;
  VL vec(N);
  rep(i,0,N){
    cin >> vec[i];
  }
  
  VL sum = vec;
  dsu D(N);
  rep(i,0,M){
    int a, b;
    cin >> a >> b;
    a--; b--;
    if(D.same(a,b)){
      continue;
    }
    int x = D.leader(a);
    int y = D.leader(b);
    D.merge(a,b);
    int z = D.leader(a);
    sum[z] = sum[x] + sum[y];
  }
  
  mint ans = 1;
  rep(i,0,N){
    if(D.leader(i) == i){
      int s = D.size(i);
      rep(j,0,s){
        ans *= sum[i];
      }
    }
  }
  cout << ans.val() << endl;
}
0