結果
問題 | No.3024 全単射的 |
ユーザー |
![]() |
提出日時 | 2025-02-14 22:58:25 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 330 ms / 5,000 ms |
コード長 | 1,376 bytes |
コンパイル時間 | 4,149 ms |
コンパイル使用メモリ | 294,776 KB |
実行使用メモリ | 38,800 KB |
最終ジャッジ日時 | 2025-02-14 22:58:44 |
合計ジャッジ時間 | 6,606 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/maxflow> using namespace std; #define For(i, a, b) for(int i = (a); i < (b); i++) #define rep(i, n) For(i, 0, n) #define rFor(i, a, b) for(int i = (a); i >= (b); i--) #define ALL(v) (v).begin(), (v).end() #define rALL(v) (v).rbegin(), (v).rend() using lint = long long; using ld = long double; int INF = 2000000000; lint LINF = 1000000000000000000; struct SetupIo { SetupIo() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); } } setupio; int main() { int n; lint m; cin >> n >> m; vector<lint> x(n), y(n), goods; rep(i, n) { cin >> x[i] >> y[i]; goods.emplace_back(x[i]); goods.emplace_back(y[i]); } sort(ALL(goods)); goods.erase(unique(ALL(goods)), goods.end()); int sz = goods.size(); atcoder::mf_graph<int> g(1 + n + sz + 1); rep(i, n) { g.add_edge(0, i + 1, 1); } rep(i, n) { int id = lower_bound(ALL(goods), x[i]) - goods.begin(); assert(goods[id] == x[i]); g.add_edge(i + 1, id + n + 1, 1); id = lower_bound(ALL(goods), y[i]) - goods.begin(); assert(goods[id] == y[i]); g.add_edge(i + 1, id + n + 1, 1); } rep(i, sz) { g.add_edge(i + n + 1, n + sz + 1, 1); } cout << g.flow(0, n + sz + 1) << "\n"; }