QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#341260#898. 二分图最大匹配Terac#RE 0ms0kbC++142.9kb2024-02-29 17:03:152024-02-29 17:03:17

Judging History

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

  • [2024-02-29 17:03:17]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-02-29 17:03:15]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
using namespace std;

namespace IO {
	#if ONLINE_JUDGE
	#define getc() (IS == IT && (IT = (IS = ibuf) + fread(ibuf, 1, IL, stdin), IS == IT) ? EOF : *IS++)
	#else
	#define getc() getchar()
	#endif
	const int IL = 1 << 21, OL = 1 << 21;
	int olen = 0;
	char ibuf[IL], *IS = ibuf, *IT = ibuf, obuf[OL];
	inline int read() {
		register char ch = getc(); register int x = 0, f = 1;
		while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getc(); }
		while(isdigit(ch)) x = x * 10 + ch - 48, ch = getc();
		return x * f;
	}
	inline double readdb() {
		register char ch = getc(); register double x = 0, f = 1;
		while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getc(); }
		while(isdigit(ch)) x = x * 10 + ch - 48, ch = getc();
		if(ch == '.') {
			register double b = 0.1;
			ch = getc();
			while(isdigit(ch)) x += (ch - 48) * b, b *= 0.1, ch = getc();
		}
		return x * f;
	}
	inline int readstr(char *s) {
		register char ch = getc(); register int len = 0;
		while(!isalpha(ch)) ch = getc();
		while(isalpha(ch)) s[++len] = ch, ch = getc();
		return len;
	}
	inline void flush() { fwrite(obuf, 1, olen, stdout); olen = 0; }
	inline void putc(register char ch) { obuf[olen++] = ch; }
	template<class T>
	inline void write(register T x) {
		if(x < 0) obuf[olen++] = '-', x = -x;
		if(x > 9) write(x / 10);
		obuf[olen++] = x % 10 + 48;
	}
} using namespace IO;
const int N = 2e5 + 10, M = 2e5 + 10;
int S, T;
struct edge {
	int to, w, nxt;
} e[M << 1];
int head[N], ecnt = 1;
void addedge(int u, int v, int w) {
	e[++ecnt] = {v, w, head[u]};
	head[u] = ecnt;
	e[++ecnt] = {u, 0, head[v]};
	head[v] = ecnt;
}
int dep[N], now[N];
bool bfs() {
	memset(dep, 0, sizeof(dep));
	queue<int> q;
	q.push(S);
	dep[S] = 1;
	while(!q.empty()) {
		int u = q.front();
		q.pop();
		now[u] = head[u];
		for(int i = head[u], v; i; i = e[i].nxt) {
			v = e[i].to;
			if(e[i].w && !dep[v]) {
				dep[v] = dep[u] + 1;
				q.push(v);
			}
		}
	}
	return dep[T];
}
ll dfs(int u, ll sum) {
	if(u == T) return sum;
	ll res = 0, flow;
	for(int i = now[u], v; i; i = e[i].nxt) {
		now[u] = i;
		v = e[i].to;
		if(dep[v] == dep[u] + 1 && e[i].w) {
			flow = dfs(v, min(sum, 1ll * e[i].w));
			e[i].w -= flow;
			e[i ^ 1].w += flow;
			sum -= flow;
			res += flow;
			if(!sum) break;
		}
	}
	if(!res) dep[u] = 0;
	return res;
}
ll dinic() { ll ans = 0; while(bfs()) ans += dfs(S, 1e18); return ans; }
int main() {
	int L = read(), R = read(), m = read();
	S = L + R + 1, T = L + R + 2;
	for(int i = 1; i <= L; i++)
		addedge(S, i, 1);
	for(int i = 1; i <= R; i++)
		addedge(L + i, T, 1);
	for(int i = 1; i <= m; i++) {
		int u = read() + 1, v = read() + 1;
		addedge(u, L + v, 1);
	}
	printf("%d\n", dinic());
	for(int u = 1; u <= L; u++)
		for(int i = head[u], v; i; i = e[i].nxt) {
			v = e[i].to;
			if(v == S) continue;
			if(!e[i].w) printf("%d %d\n", u - 1, v - L - 1);
		}
	return 0;
}

詳細信息

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: