結果

問題 No.1390 Get together
ユーザー 👑 NachiaNachia
提出日時 2021-02-12 23:52:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 667 bytes
コンパイル時間 1,886 ms
コンパイル使用メモリ 201,444 KB
実行使用メモリ 7,120 KB
最終ジャッジ日時 2023-09-27 07:40:31
合計ジャッジ時間 4,364 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 44 ms
7,012 KB
testcase_17 AC 50 ms
6,948 KB
testcase_18 AC 45 ms
7,096 KB
testcase_19 AC 51 ms
7,100 KB
testcase_20 AC 58 ms
7,036 KB
testcase_21 AC 58 ms
7,040 KB
testcase_22 AC 53 ms
7,088 KB
testcase_23 AC 53 ms
7,120 KB
testcase_24 AC 53 ms
7,000 KB
testcase_25 AC 51 ms
7,012 KB
testcase_26 AC 51 ms
7,112 KB
testcase_27 AC 51 ms
7,000 KB
testcase_28 AC 51 ms
7,112 KB
testcase_29 AC 52 ms
6,992 KB
testcase_30 AC 51 ms
7,100 KB
testcase_31 AC 51 ms
7,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

struct dsu{
  vector<int> V;
  dsu(int n){ V.assign(n,-1); }
  int leader(int a){ return V[a]>=0?V[a]=leader(V[a]):a; }
  void merge(int r,int c){ if((c=leader(c))!=(r=leader(r))) V[c]=r; }
};


int N,M;
int B[200000];
int C[200000];

int main(){
  scanf("%d%d",&N,&M);
  rep(i,N){ scanf("%d%d",&B[i],&C[i]); B[i]--; C[i]--; }
  dsu G(N+M);
  rep(i,N) G.merge(C[i]+M,B[i]);
  vector<int> cnt(N);
  rep(i,M) if(G.leader(i)>=M) cnt[G.leader(i)-M]++;
  int ans=0; rep(i,N) ans+=max(0,cnt[i]-1);
  printf("%d\n",ans);
  return 0;
}
0