QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#126573#898. 二分图最大匹配1234567890#TL 0ms0kbC++202.7kb2023-07-18 17:38:582023-07-18 17:39:01

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-18 17:39:01]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-07-18 17:38:58]
  • 提交

answer

/*
灏忓簾鐗╋紝杩欓兘涓嶄細 /cf
*/
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define mp make_pair
#define inf (ll)1e9
#define pii pair <ll, ll>
#define fr first
#define se second
const ll mod = 1e9 + 7;
char buf[1 << 21], *p1 = buf, *p2 = buf;
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 18, stdin), p1 == p2) ? EOF : *p1++)
inline ll read() {
	ll x = 0, f = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9') f = ((ch == '-') ? -1 : f), ch = getchar();
	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	return x * f;
}
inline void write(ll x) {
	if(x < 0) x = -x, putchar('-');
	if(x >= 10) write(x / 10);
	putchar(x % 10 + '0');
}
struct Flow {
	ll s, t, N;
	ll tot = 1;
	struct Edge {
		ll v, e, nxt;
	}edge[1000005];
	ll head[200005], cur[200005], dis[200005];
	inline void addedge(ll u, ll v, ll e) {
		edge[++tot].v = v, edge[tot].e = e, edge[tot].nxt = head[u], head[u] = tot;
	}
	inline void Addedge(ll u, ll v, ll e) {
		addedge(u, v, e);
		addedge(v, u, 0);
	} 
	inline bool bfs() {
		for(ll i = 0; i <= N; i++) dis[i] = inf, cur[i] = head[i];
		dis[s] = 0;
		queue <ll> Q;
		Q.push(s);
		while(!Q.empty()) {
			ll x = Q.front();
			Q.pop();
			for(ll i = head[x]; i; i = edge[i].nxt) {
				ll v = edge[i].v, e = edge[i].e;
				if(dis[v] > dis[x] + 1 && e) {
					dis[v] = dis[x] + 1;
					Q.push(v);
				}
			}
		}
		return dis[t] != dis[0];
	}
	inline ll dfs(ll x, ll ne) {
		if(x == t) return ne;
		ll now = 0, used = 0;
		for(ll i = cur[x]; i; i = edge[i].nxt) {
			cur[x] = i;
			ll v = edge[i].v, e = edge[i].e;
			if(dis[v] == dis[x] + 1 && e) {
				now = dfs(v, min(e, ne - used));
				if(now) {
					edge[i].e -= now;
					edge[i^1].e += now;
					used += now;
					if(used == now) break; 
				}
			}
		}
		return used;
	}
	inline ll Dinic() {
		ll ans = 0;
		while(bfs()) ans += dfs(s, inf);
		return ans;
	}
}F;
vector <pii> Ans;
int main() {
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	ll nl = read(), nr = read(), m = read();
//	assert(nl == 4 && nr == 4 && m == 7);
	F.s = nl + nr + 1, F.t = F.N = F.s + 1;
	for(ll i = 1; i <= nl; i++) F.Addedge(F.s, i, 1);
	for(ll i = nl + 1; i <= nl + nr; i++) F.Addedge(i, F.t, 1);
	for(ll i = 1; i <= m; i++) {
		ll u = read() + 1, v = read() + 1 + nl;
		F.Addedge(u, v, 1);
	}
	ll aans = F.Dinic();
	Ans.reserve(aans);
	write(aans), putchar('\n');
	for(ll i = 1; i <= nl; i++) {
		for(ll j = F.head[i]; j; j = F.edge[j].nxt) if(F.edge[j].v > nl && F.edge[j].v <= nl + nr && !F.edge[j].e) Ans.push_back(mp(i, F.edge[j].v));
	}
	for(auto i : Ans) write(i.fr - 1), putchar(' '), write(i.se - 1 - nl), putchar('\n');
	return 0;
}
/*
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time 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: