QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#791595#898. 二分图最大匹配Mr_MinML 0ms0kbC++14791b2024-11-28 19:47:102024-11-28 19:47:12

Judging History

你现在查看的是最新测评结果

  • [2024-11-28 19:47:12]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:0kb
  • [2024-11-28 19:47:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
constexpr int N = 1e5 + 5;
bitset < N > to[N], vis, ave;
int l, r, m, mch[N];
int dfs(int u) {
  if (vis[u]) return 0;
  vis[u] = 1;
  while (1) {
    int v = (to[u] & ave)._Find_first();
    if (v == N) return 0;
    ave[v] = 0;
    if (!mch[v] || dfs(mch[v])) return mch[v] = u, 1;
  }
  return 0;
}

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  cin >> l >> r >> m;
  for (int i = 1, u, v; i <= m; i++) {
    cin >> u >> v; u++, v++;
    to[u][v] = 1;
  }
  int ret = 0;
  for (int i = 1; i <= l; i++) ave.set(), vis.reset(), ret += dfs(i);
  cout << ret << '\n';
  for (int i = 1; i <= l; i++) {
    if (mch[i]) cout << i - 1 << ' ' << mch[i] - 1 << '\n';
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Memory Limit Exceeded

input:

100000 100000 200000
78474 45795
32144 46392
92549 13903
73460 34144
96460 92850
56318 77066
77529 84436
76342 51542
77506 99268
76410 89381
1778 61392
43607 96135
84268 74827
14857 35966
32084 94908
19876 174
1481 94390
12423 55019
64368 92587
81295 7902
25432 46032
36293 61128
73555 84836
8418 102...

output:


result: