QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#480300#898. 二分图最大匹配_l_l_#RE 0ms0kbC++141.7kb2024-07-16 13:00:002024-07-16 13:00:00

Judging History

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

  • [2024-07-16 13:00:00]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-07-16 13:00:00]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
const int MAXM = 200005;
struct edge {int to, val, nxt;} edges[MAXM << 1]; int head[MAXN], tot = 1;
void add(int u, int v, int w) {
	edges[++tot].to = v; edges[tot].val = w; edges[tot].nxt = head[u]; head[u] = tot;
}
int key[MAXN], dep[MAXN];
bool bfs(int s, int t, int n) {
	for (int i = 1; i <= n; i++) key[i] = head[i], dep[i] = 0;
	dep[s] = 1; queue<int> q; q.push(s); while (q.empty() == 0) {
		int u = q.front(); q.pop(); for (int i = head[u]; i; i = edges[i].nxt) {
			if (edges[i].val && dep[edges[i].to] == 0) {
				dep[edges[i].to] = dep[u] + 1; q.push(edges[i].to);
			}
		}
	} return dep[t];
}
int dfs(int u, int f, int t) {
	if (f == 0 || u == t) return f; int ans = 0;
	for (int &i = key[u]; i; i = edges[i].nxt) {
		if (dep[edges[i].to] != dep[u] + 1) continue;
		int x = dfs(edges[i].to, min(f - ans, edges[i].val), t);
		edges[i].val -= x; edges[i ^ 1].val += x; ans += x;
		if (ans == f) break;
	}
	return ans;
}
int flow(int s, int t, int n) {
	int ans = 0; while (bfs(s, t, n)) ans += dfs(s, 0x7fffffff, t); return ans;
}
int main() {
	int l, r, m; scanf("%d %d %d", &l, &r, &m);
	int s = l + r + 1, t = s + 1;
	for (int i = 1; i <= m; i++) {
		int u, v; scanf("%d %d", &u, &v); u++; v++;
		add(u, v + l, 1); add(v + l, u, 0);
	}
	for (int i = 1; i <= l; i++) add(s, i, 1), add(i, s, 0);
	for (int i = 1; i <= r; i++) add(i + l, t, 1), add(t, i + l, 0);
	printf("%d\n", flow(s, t, t));
	for (int i = 1; i <= l; i++) {
		for (int j = head[i]; j; j = edges[j].nxt) {
			if (edges[j].to > l && edges[j].to <= l + r && edges[j].val == 0) {
				printf("%d %d\n", i - 1, edges[j].to - l - 1);
			}
		}
	}
}

详细

Test #1:

score: 0
Runtime Error

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: