結果
問題 |
No.1390 Get together
|
ユーザー |
👑 ![]() |
提出日時 | 2021-02-12 23:52:52 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 60 ms / 2,000 ms |
コード長 | 667 bytes |
コンパイル時間 | 1,996 ms |
コンパイル使用メモリ | 195,184 KB |
最終ジャッジ日時 | 2025-01-18 19:56:35 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:20:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 20 | scanf("%d%d",&N,&M); | ~~~~~^~~~~~~~~~~~~~ main.cpp:21:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 21 | rep(i,N){ scanf("%d%d",&B[i],&C[i]); B[i]--; C[i]--; } | ~~~~~^~~~~~~~~~~~~~~~~~~~
ソースコード
#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; }