結果
| 問題 |
No.1390 Get together
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2021-02-12 23:45:58 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 650 bytes |
| コンパイル時間 | 1,959 ms |
| コンパイル使用メモリ | 197,108 KB |
| 最終ジャッジ日時 | 2025-01-18 19:55:35 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 11 MLE * 18 |
コンパイルメッセージ
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){ 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;
}
Nachia