結果
| 問題 |
No.3024 全単射的
|
| コンテスト | |
| ユーザー |
kmjp
|
| 提出日時 | 2025-02-14 23:21:51 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,943 bytes |
| コンパイル時間 | 2,467 ms |
| コンパイル使用メモリ | 207,704 KB |
| 実行使用メモリ | 21,400 KB |
| 最終ジャッジ日時 | 2025-02-14 23:29:08 |
| 合計ジャッジ時間 | 3,794 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 WA * 4 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------
int N,M;
ll A[101010],B[101010];
template<int um> class UF {
public:
vector<int> par,rank,cnt,G[um];
UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
void reinit(int num=um) {int i; FOR(i,num) rank[i]=0,cnt[i]=1,par[i]=i;}
int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
int count(int x) { return cnt[operator[](x)];}
int operator()(int x,int y) {
if((x=operator[](x))==(y=operator[](y))) return x;
cnt[y]=cnt[x]=cnt[x]+cnt[y];
if(rank[x]>rank[y]) return par[x]=y;
rank[x]+=rank[x]==rank[y]; return par[y]=x;
}
};
UF<404040> uf;
int E[404040];
void solve() {
int i,j,k,l,r,x,y; string s;
vector<ll> Xs;
cin>>N>>M;
FOR(i,N) {
cin>>A[i]>>B[i];
Xs.push_back(A[i]);
Xs.push_back(B[i]);
}
sort(ALL(Xs));
Xs.erase(unique(ALL(Xs)),Xs.end());
M=Xs.size();
FOR(i,N) {
x=lower_bound(ALL(Xs),A[i])-Xs.begin();
y=lower_bound(ALL(Xs),B[i])-Xs.begin();
x=uf[x];
y=uf[y];
if(x==y) {
E[x]++;
}
else {
E[x]=E[y]=E[x]+E[y]+1;
uf(x,y);
}
}
int ret=0;
FOR(i,M) if(uf[i]==i) ret+=min(uf.count(i),E[i]);
cout<<ret<<endl;
}
int main(int argc,char** argv){
string s;int i;
if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
cout.tie(0); solve(); return 0;
}
kmjp