QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#44652#898. 二分图最大匹配Remakee#RE 0ms0kbC++142.2kb2022-08-20 16:53:152022-08-20 16:53:18

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-08-20 16:53:18]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2022-08-20 16:53:15]
  • 提交

answer

// Skyqwq
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;

typedef pair<int, int> PII;
typedef long long LL;

template <typename T> bool inline chkMin(T &x, T y) { return (y < x) ? x = y, 1 : 0; }
template <typename T> bool inline chkMax(T &x, T y) { return (y > x) ? x = y, 1 : 0; }

template <typename T> void inline read(T &x) {
	x = 0; int f = 1; char s = getchar();
	while (s > '9' || s < '0') { if (s == '-') f = -1; s = getchar(); }
	while (s <= '9' && s >= '0') x = x * 10 + s - '0', s = getchar();
	x *= f;
}

const int N = 2e5 + 5, M = 2e5 + 5;

const LL INF = 1e18;

int n, m, s, t, v, A[M], B[M], C[M];

struct E{
	int next, v, w;
} e[M << 1];

int head[N], numE = 1;

void add(int u, int v, int w) {
	e[++numE] = (E) { head[u], v, w };
	head[u] = numE;
}

void addE(int u, int v, int w) {
	add(u, v, w), add(v, u, 0);
}

int q[N], d[N], cur[N];

bool bfs() {
	memset(d, 0x3f, sizeof d);
	d[s] = 0;
	int hh = 0, tt = 0;
	q[0] = s; cur[s] = head[s];
	while (hh <= tt) {
		int u = q[hh++];
		for (int i = head[u]; i; i = e[i].next) {
			int v = e[i].v;
			if (e[i].w && d[u] + 1 < d[v]) {
				d[v] = d[u] + 1;
				q[++tt] = v; cur[v] = head[v];
				if (v == t) return 1;
			}
		}
	}
	return 0;
}

LL dinic(int u, LL flow) {
	if (u == t) return flow;
	LL rest = flow;
	for (int i = head[u]; i && rest; i = e[i].next) {
		int v = e[i].v;
		if (e[i].w && d[u] + 1 == d[v]) {
			LL k = dinic(v, min((LL)e[i].w, rest));
			if (!k) d[v] = 0;
			else {
				e[i].w -= k, e[i ^ 1].w += k, rest -= k;
			}
		}
	}
	return flow - rest;
}

int main() {
	int L, R, m; read(L), read(R), read(m);
	n = L + R + 2;
	s = n - 1, t = n;
//	read(n), read(m); read(s), read(t);	
	for (int i = 1; i <= m; i++) {
		int u, v; read(u), read(v);
		++u, ++v;
		addE(u, v + L, 1);
		A[i] = u, B[i] = v, C[i] = numE;
	}
	for (int i = 1; i <= L; i++) addE(s, i, 1);
	for (int i = 1; i <= R; i++) addE(i + L, t, 1);
	LL ans = 0, ret = 0;
	while (bfs()) {
		while (ret = dinic(s, INF)) ans += ret;
	}
	printf("%lld\n", ans);
	for (int i = 1; i <= m; i++) {
		if (e[C[i]].w) printf("%d %d\n", A[i] - 1, B[i] - 1);
	}
	return 0;
}



Details

Tip: Click on the bar to expand more detailed information

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: