QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#791664#898. 二分图最大匹配Mr_MinWA 58ms9852kbC++14963b2024-11-28 20:11:512024-11-28 20:11:56

Judging History

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

  • [2024-11-28 20:11:56]
  • 评测
  • 测评结果:WA
  • 用时:58ms
  • 内存:9852kb
  • [2024-11-28 20:11:51]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
constexpr int N = 1e5 + 5;
vector < int > g[N];
int l, r, m, mch[N], vis[N];
int dfs(int u, int t) {
  if (vis[u] == t) return 0;
  vis[u] = t;
  for (int v : g[u]) {
    if (mch[v] < 0) return mch[v] = u, 1;
  }
  for (int v : g[u]) {
    if (vis[v] != t && dfs(mch[v], t)) return mch[v] = u, 1;
  }
  return 0;
}

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  cin >> l >> r >> m;
  memset(mch, -1, sizeof(mch));
  memset(vis, -1, sizeof(vis));
  for (int i = 1, u, v; i <= m; i++) {
    cin >> u >> v;
    g[u].push_back(v);
  }
  int ret = 0;
  vector < int > ord(l);
  iota(ord.begin(), ord.end(), 0);
  mt19937 rng(random_device{}());
  shuffle(ord.begin(), ord.end(), rng);
  for (int i : ord) ret += dfs(i, i);
  cout << ret << '\n';
  for (int i = 0; i < r; i++) {
    if (~mch[i]) cout << mch[i] << ' ' << i << '\n';
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 58ms
memory: 9852kb

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:

99943
63893 0
88633 1
5283 2
69829 3
94676 4
90712 5
92014 6
59953 7
71269 8
58488 9
43951 10
20110 11
30466 12
60846 13
52381 14
59008 15
62176 16
35924 17
78013 18
21527 19
85970 20
47990 21
90601 22
76846 23
36019 24
49446 25
97056 26
38043 27
24373 28
25033 29
47321 30
59580 31
78298 32
4755 33
...

result:

wrong answer # of Matching is differ - expected: '100000', found '99943'