結果
| 問題 |
No.3024 全単射的
|
| コンテスト | |
| ユーザー |
shobonvip
|
| 提出日時 | 2025-02-14 21:34:08 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,156 bytes |
| コンパイル時間 | 4,419 ms |
| コンパイル使用メモリ | 257,544 KB |
| 実行使用メモリ | 8,196 KB |
| 最終ジャッジ日時 | 2025-02-14 21:34:14 |
| 合計ジャッジ時間 | 5,444 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 WA * 4 |
ソースコード
/**
author: shobonvip
created: 2025.02.14 21:31:06
**/
#include<bits/stdc++.h>
using namespace std;
//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/
/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/
typedef long long ll;
#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)
#define all(v) v.begin(), v.end()
template <typename T> bool chmin(T &a, const T &b) {
if (a <= b) return false;
a = b;
return true;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a >= b) return false;
a = b;
return true;
}
template <typename T> T max(vector<T> &a){
assert(!a.empty());
T ret = a[0];
for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
return ret;
}
template <typename T> T min(vector<T> &a){
assert(!a.empty());
T ret = a[0];
for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
return ret;
}
template <typename T> T sum(vector<T> &a){
T ret = 0;
for (int i=0; i<(int)a.size(); i++) ret += a[i];
return ret;
}
// defcomp
template <typename T>
vector<T> compress(vector<T> &X) {
vector<T> vals = X;
sort(vals.begin(), vals.end());
vals.erase(unique(vals.begin(), vals.end()), vals.end());
return vals;
}
// -----
// importbisect
template <typename T>
int bisect_left(vector<T> &X, T v){
return lower_bound(X.begin(), X.end(), v) - X.begin();
}
template <typename T>
int bisect_right(vector<T> &X, T v){
return upper_bound(X.begin(), X.end(), v) - X.begin();
}
// -----
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m;
cin >> n >> m;
vector<ll> x(n),y(n);
vector<ll> v;
rep(i,0,n){
cin>>x[i]>>y[i];
v.push_back(x[i]);
v.push_back(y[i]);
}
v = compress(v);
rep(i,0,n){
x[i]=bisect_left(v,x[i]);
y[i]=bisect_left(v,y[i]);
}
int k=v.size();
dsu uf(k);
vector<int> order(k);
rep(i,0,n){
uf.merge(x[i],y[i]);
}
rep(i,0,n){
order[uf.leader(x[i])]++;
}
int ans=0;
rep(i,0,k){
if(uf.leader(i)==i){
int sz = uf.size(i);
ans+=min(sz,order[i]);
}
}
cout<<ans<<endl;
}
shobonvip