This documentation is automatically generated by competitive-verifier/competitive-verifier
// competitive-verifier: PROBLEM https://onlinejudge.u-aizu.ac.jp/problems/3032
// competitive-verifier: TLE 0.5
// competitive-verifier: MLE 64
#include <iostream>
#include <algorithm>
#include "src/Graph/Graph.hpp"
#include "src/Graph/general_matching.hpp"
using namespace std;
signed main() {
cin.tie(0);
ios::sync_with_stdio(0);
int N, A, B;
cin >> N >> A >> B;
Graph g(2 * N);
int a[N], b[N];
for (int i= 0; i < N; i++) cin >> a[i] >> b[i];
for (int i= 0; i < N; i++) {
if (abs(a[i] - b[i]) <= A || (B <= abs(a[i] - b[i]) && abs(a[i] - b[i]) <= 2 * A)) g.add_edge(i, i + N);
for (int j= i + 1; j < N; j++) {
int tmp= abs(a[i] + a[j] - b[i] - b[j]);
if (tmp <= A || (B <= tmp && tmp <= 2 * A)) g.add_edge(i, j);
}
}
auto [ans, _]= general_matching(g);
cout << ans.size() << '\n';
return 0;
}
#line 1 "test/aoj/3032.test.cpp"
// competitive-verifier: PROBLEM https://onlinejudge.u-aizu.ac.jp/problems/3032
// competitive-verifier: TLE 0.5
// competitive-verifier: MLE 64
#include <iostream>
#include <algorithm>
#line 2 "src/Internal/ListRange.hpp"
#include <vector>
#line 4 "src/Internal/ListRange.hpp"
#include <iterator>
#include <type_traits>
#define _LR(name, IT, CT) \
template <class T> struct name { \
using Iterator= typename std::vector<T>::IT; \
Iterator bg, ed; \
Iterator begin() const { return bg; } \
Iterator end() const { return ed; } \
size_t size() const { return std::distance(bg, ed); } \
CT &operator[](int i) const { return bg[i]; } \
}
_LR(ListRange, iterator, T);
_LR(ConstListRange, const_iterator, const T);
#undef _LR
template <class T> struct CSRArray {
std::vector<T> dat;
std::vector<int> p;
size_t size() const { return p.size() - 1; }
ListRange<T> operator[](int i) { return {dat.begin() + p[i], dat.begin() + p[i + 1]}; }
ConstListRange<T> operator[](int i) const { return {dat.cbegin() + p[i], dat.cbegin() + p[i + 1]}; }
};
template <template <class> class F, class T> std::enable_if_t<std::disjunction_v<std::is_same<F<T>, ListRange<T>>, std::is_same<F<T>, ConstListRange<T>>, std::is_same<F<T>, CSRArray<T>>>, std::ostream &> operator<<(std::ostream &os, const F<T> &r) {
os << '[';
for (int _= 0, __= r.size(); _ < __; ++_) os << (_ ? ", " : "") << r[_];
return os << ']';
}
#line 3 "src/Graph/Graph.hpp"
struct Edge: std::pair<int, int> {
using std::pair<int, int>::pair;
Edge &operator--() { return --first, --second, *this; }
int to(int v) const { return first ^ second ^ v; }
friend std::istream &operator>>(std::istream &is, Edge &e) { return is >> e.first >> e.second, is; }
};
struct Graph: std::vector<Edge> {
size_t n;
Graph(size_t n= 0, size_t m= 0): vector(m), n(n) {}
size_t vertex_size() const { return n; }
size_t edge_size() const { return size(); }
size_t add_vertex() { return n++; }
size_t add_edge(int s, int d) { return emplace_back(s, d), size() - 1; }
size_t add_edge(Edge e) { return emplace_back(e), size() - 1; }
#define _ADJ_FOR(a, b) \
for (auto [u, v]: *this) a; \
for (size_t i= 0; i < n; ++i) p[i + 1]+= p[i]; \
for (int i= size(); i--;) { \
auto [u, v]= (*this)[i]; \
b; \
}
#define _ADJ(a, b) \
vector<int> p(n + 1), c(size() << !dir); \
if (!dir) { \
_ADJ_FOR((++p[u], ++p[v]), (c[--p[u]]= a, c[--p[v]]= b)) \
} else if (dir > 0) { \
_ADJ_FOR(++p[u], c[--p[u]]= a) \
} else { \
_ADJ_FOR(++p[v], c[--p[v]]= b) \
} \
return {c, p}
CSRArray<int> adjacency_vertex(int dir) const { _ADJ(v, u); }
CSRArray<int> adjacency_edge(int dir) const { _ADJ(i, i); }
#undef _ADJ
#undef _ADJ_FOR
};
#line 2 "src/Graph/general_matching.hpp"
#include <cassert>
#line 4 "src/Graph/general_matching.hpp"
// {matching edge ids, partner(-1 if unmatched)}
std::pair<std::vector<int>, std::vector<int>> general_matching(const Graph &g, std::vector<int> partner= {}) {
auto adj= g.adjacency_vertex(0);
const int n= adj.size();
std::vector<int> q, z(n), p(n);
if (partner.empty()) partner.assign(n, -1);
assert((int)partner.size() == n);
std::vector<Edge> fs(n);
auto rematch= [&](auto &&rc, int u, int v) -> void {
int w= partner[u];
if (partner[u]= v; w == -1 || partner[w] != u) return;
if (auto [x, y]= fs[u]; y == -1) rc(rc, partner[w]= x, w);
else rc(rc, x, y), rc(rc, y, x);
};
int t= 1;
auto f= [&](auto &&rc, int x) -> int { return z[x] != t || p[x] == -1 ? x : (p[x]= rc(rc, p[x])); };
auto check= [&](int r) {
q.clear(), q.push_back(r), fs[r]= {-1, -1}, z[r]= t, p[r]= -1;
for (int i= 0; i < (int)q.size(); ++i) {
int x= q[i];
for (int y: adj[x]) {
if (y == r) continue;
if (partner[y] == -1) return rematch(rematch, partner[y]= x, y), true;
if (z[y] == t) {
int u= f(f, x), v= f(f, y), w= r;
if (u == v) continue;
for (; u != r || v != r; fs[u]= {x, y}, u= f(f, fs[partner[u]].first)) {
if (v != r) std::swap(u, v);
if (fs[u].first == x && fs[u].second == y) {
w= u;
break;
}
}
for (int a: {f(f, x), f(f, y)})
for (; a != w; a= f(f, fs[partner[a]].first)) z[a]= t, p[a]= w, q.push_back(a);
} else if (z[partner[y]] != t) fs[y]= {-1, -1}, fs[partner[y]]= {x, -1}, z[partner[y]]= t, p[partner[y]]= y, q.push_back(partner[y]);
}
}
return false;
};
for (int r= n; r--;)
if (partner[r] == -1) t+= check(r);
q.clear();
for (int i= 0, e= g.edge_size(); i < e; ++i)
if (auto [u, v]= g[i]; partner[u] == v && z[u] >= 0) q.push_back(i), z[u]= z[v]= -1;
return {q, partner};
}
#line 8 "test/aoj/3032.test.cpp"
using namespace std;
signed main() {
cin.tie(0);
ios::sync_with_stdio(0);
int N, A, B;
cin >> N >> A >> B;
Graph g(2 * N);
int a[N], b[N];
for (int i= 0; i < N; i++) cin >> a[i] >> b[i];
for (int i= 0; i < N; i++) {
if (abs(a[i] - b[i]) <= A || (B <= abs(a[i] - b[i]) && abs(a[i] - b[i]) <= 2 * A)) g.add_edge(i, i + N);
for (int j= i + 1; j < N; j++) {
int tmp= abs(a[i] + a[j] - b[i] - b[j]);
if (tmp <= A || (B <= tmp && tmp <= 2 * A)) g.add_edge(i, j);
}
}
auto [ans, _]= general_matching(g);
cout << ans.size() << '\n';
return 0;
}
Env | Name | Status | Elapsed | Memory |
---|---|---|---|---|
g++-13 | 00_sample_00.in |
![]() |
6 ms | 4 MB |
g++-13 | 00_sample_01.in |
![]() |
5 ms | 4 MB |
g++-13 | 01_small_00.in |
![]() |
5 ms | 4 MB |
g++-13 | 01_small_01.in |
![]() |
5 ms | 4 MB |
g++-13 | 01_small_02.in |
![]() |
5 ms | 4 MB |
g++-13 | 01_small_03.in |
![]() |
5 ms | 4 MB |
g++-13 | 01_small_04.in |
![]() |
5 ms | 4 MB |
g++-13 | 01_small_05.in |
![]() |
5 ms | 4 MB |
g++-13 | 01_small_06.in |
![]() |
5 ms | 4 MB |
g++-13 | 01_small_07.in |
![]() |
5 ms | 4 MB |
g++-13 | 01_small_08.in |
![]() |
5 ms | 4 MB |
g++-13 | 01_small_09.in |
![]() |
5 ms | 4 MB |
g++-13 | 01_small_10.in |
![]() |
5 ms | 4 MB |
g++-13 | 01_small_11.in |
![]() |
5 ms | 4 MB |
g++-13 | 01_small_12.in |
![]() |
5 ms | 4 MB |
g++-13 | 01_small_13.in |
![]() |
5 ms | 4 MB |
g++-13 | 01_small_14.in |
![]() |
5 ms | 4 MB |
g++-13 | 01_small_15.in |
![]() |
5 ms | 4 MB |
g++-13 | 01_small_16.in |
![]() |
5 ms | 4 MB |
g++-13 | 01_small_17.in |
![]() |
5 ms | 4 MB |
g++-13 | 01_small_18.in |
![]() |
5 ms | 4 MB |
g++-13 | 01_small_19.in |
![]() |
5 ms | 3 MB |
g++-13 | 02_random_00.in |
![]() |
8 ms | 6 MB |
g++-13 | 02_random_01.in |
![]() |
6 ms | 4 MB |
g++-13 | 02_random_02.in |
![]() |
5 ms | 4 MB |
g++-13 | 02_random_03.in |
![]() |
8 ms | 6 MB |
g++-13 | 02_random_04.in |
![]() |
6 ms | 4 MB |
g++-13 | 02_random_05.in |
![]() |
9 ms | 8 MB |
g++-13 | 02_random_06.in |
![]() |
7 ms | 4 MB |
g++-13 | 02_random_07.in |
![]() |
6 ms | 4 MB |
g++-13 | 02_random_08.in |
![]() |
5 ms | 4 MB |
g++-13 | 02_random_09.in |
![]() |
5 ms | 4 MB |
g++-13 | 03_large_00.in |
![]() |
11 ms | 9 MB |
g++-13 | 03_large_01.in |
![]() |
9 ms | 5 MB |
g++-13 | 03_large_02.in |
![]() |
6 ms | 4 MB |
g++-13 | 03_large_03.in |
![]() |
11 ms | 10 MB |
g++-13 | 03_large_04.in |
![]() |
8 ms | 4 MB |
g++-13 | 03_large_05.in |
![]() |
11 ms | 10 MB |
g++-13 | 03_large_06.in |
![]() |
12 ms | 11 MB |
g++-13 | 03_large_07.in |
![]() |
13 ms | 10 MB |
g++-13 | 03_large_08.in |
![]() |
13 ms | 11 MB |
g++-13 | 03_large_09.in |
![]() |
12 ms | 10 MB |
clang++-18 | 00_sample_00.in |
![]() |
6 ms | 4 MB |
clang++-18 | 00_sample_01.in |
![]() |
5 ms | 4 MB |
clang++-18 | 01_small_00.in |
![]() |
5 ms | 4 MB |
clang++-18 | 01_small_01.in |
![]() |
5 ms | 4 MB |
clang++-18 | 01_small_02.in |
![]() |
5 ms | 4 MB |
clang++-18 | 01_small_03.in |
![]() |
5 ms | 4 MB |
clang++-18 | 01_small_04.in |
![]() |
5 ms | 4 MB |
clang++-18 | 01_small_05.in |
![]() |
5 ms | 4 MB |
clang++-18 | 01_small_06.in |
![]() |
5 ms | 4 MB |
clang++-18 | 01_small_07.in |
![]() |
5 ms | 4 MB |
clang++-18 | 01_small_08.in |
![]() |
5 ms | 4 MB |
clang++-18 | 01_small_09.in |
![]() |
5 ms | 4 MB |
clang++-18 | 01_small_10.in |
![]() |
5 ms | 4 MB |
clang++-18 | 01_small_11.in |
![]() |
5 ms | 4 MB |
clang++-18 | 01_small_12.in |
![]() |
5 ms | 4 MB |
clang++-18 | 01_small_13.in |
![]() |
5 ms | 4 MB |
clang++-18 | 01_small_14.in |
![]() |
5 ms | 4 MB |
clang++-18 | 01_small_15.in |
![]() |
5 ms | 4 MB |
clang++-18 | 01_small_16.in |
![]() |
5 ms | 4 MB |
clang++-18 | 01_small_17.in |
![]() |
5 ms | 4 MB |
clang++-18 | 01_small_18.in |
![]() |
5 ms | 4 MB |
clang++-18 | 01_small_19.in |
![]() |
5 ms | 4 MB |
clang++-18 | 02_random_00.in |
![]() |
8 ms | 6 MB |
clang++-18 | 02_random_01.in |
![]() |
6 ms | 4 MB |
clang++-18 | 02_random_02.in |
![]() |
5 ms | 4 MB |
clang++-18 | 02_random_03.in |
![]() |
8 ms | 5 MB |
clang++-18 | 02_random_04.in |
![]() |
6 ms | 4 MB |
clang++-18 | 02_random_05.in |
![]() |
9 ms | 7 MB |
clang++-18 | 02_random_06.in |
![]() |
6 ms | 4 MB |
clang++-18 | 02_random_07.in |
![]() |
5 ms | 4 MB |
clang++-18 | 02_random_08.in |
![]() |
5 ms | 4 MB |
clang++-18 | 02_random_09.in |
![]() |
5 ms | 4 MB |
clang++-18 | 03_large_00.in |
![]() |
11 ms | 9 MB |
clang++-18 | 03_large_01.in |
![]() |
8 ms | 5 MB |
clang++-18 | 03_large_02.in |
![]() |
6 ms | 4 MB |
clang++-18 | 03_large_03.in |
![]() |
11 ms | 11 MB |
clang++-18 | 03_large_04.in |
![]() |
7 ms | 4 MB |
clang++-18 | 03_large_05.in |
![]() |
10 ms | 11 MB |
clang++-18 | 03_large_06.in |
![]() |
11 ms | 11 MB |
clang++-18 | 03_large_07.in |
![]() |
11 ms | 10 MB |
clang++-18 | 03_large_08.in |
![]() |
11 ms | 11 MB |
clang++-18 | 03_large_09.in |
![]() |
11 ms | 10 MB |