結果

問題 No.1390 Get together
ユーザー 👑 NachiaNachia
提出日時 2021-02-12 23:45:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 650 bytes
コンパイル時間 2,330 ms
コンパイル使用メモリ 202,120 KB
実行使用メモリ 814,592 KB
最終ジャッジ日時 2023-09-27 07:32:36
合計ジャッジ時間 4,216 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,376 KB
testcase_05 MLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

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){ V[leader(c)]=leader(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