結果

問題 No.1390 Get together
ユーザー yansi819yansi819
提出日時 2024-05-01 12:31:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 311 ms / 2,000 ms
コード長 617 bytes
コンパイル時間 4,540 ms
コンパイル使用メモリ 269,320 KB
実行使用メモリ 32,092 KB
最終ジャッジ日時 2024-05-01 12:31:15
合計ジャッジ時間 9,802 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 5 ms
6,940 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 4 ms
6,944 KB
testcase_06 AC 4 ms
6,940 KB
testcase_07 AC 4 ms
6,944 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 5 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 201 ms
25,216 KB
testcase_17 AC 147 ms
19,284 KB
testcase_18 AC 311 ms
32,092 KB
testcase_19 AC 188 ms
22,904 KB
testcase_20 AC 186 ms
22,764 KB
testcase_21 AC 187 ms
22,796 KB
testcase_22 AC 214 ms
27,496 KB
testcase_23 AC 229 ms
27,396 KB
testcase_24 AC 250 ms
27,240 KB
testcase_25 AC 187 ms
22,808 KB
testcase_26 AC 182 ms
22,892 KB
testcase_27 AC 186 ms
22,740 KB
testcase_28 AC 185 ms
22,824 KB
testcase_29 AC 216 ms
22,824 KB
testcase_30 AC 182 ms
22,872 KB
testcase_31 AC 188 ms
22,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
  int N, M; cin >> N >> M;
  vector<set<int>> cnt(N);
  dsu uf(M);

  for (int i = 0; i < N; i++) {
    int b, c; cin >> b >> c;
    b--, c--;
    cnt[c].insert(b);
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    set<int> s;
    for (auto v: cnt[i]) {
       s.insert(uf.leader(v));
    }
    ans += max(0, (int)s.size() - 1);
    for (auto v: s) {
      uf.merge(*s.begin(), v);
    }
  }
  cout << ans << endl;
  return 0;
}
0