QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#92937#898. 二分图最大匹配Joyslog#TL 81ms16708kbC++141.3kb2023-03-31 08:51:002023-03-31 08:51:03

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-31 08:51:03]
  • 评测
  • 测评结果:TL
  • 用时:81ms
  • 内存:16708kb
  • [2023-03-31 08:51:00]
  • 提交

answer

#include <bits/stdc++.h>
#define pb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

inline ll read() {
	ll ret = 0, w = 1; char c = getchar();
	while(!isdigit(c))	{if(c == '-')	w = -1; c = getchar();}
	while(isdigit(c))	{ret = (ret << 1) + (ret << 3) + (c ^ 48); c = getchar();}
	return ret * w;	
}

char buf[50];
inline void write(ll x) {
	if(x < 0)	x = -x, putchar('-');
	int tp = 0;
	do { buf[++tp] = x % 10 + 48; x /= 10;} while(x);
	while(tp)	putchar(buf[tp--]);
}

const int MAX_N = 2e5 + 10;
int n, m, e, cnt, match[MAX_N], vis[MAX_N];
pii ans[MAX_N];
vector<int> E[MAX_N];

bool dfs(int u, int tim) {
	if(vis[u] == tim)	return false;
	vis[u] = tim;
	for(int v : E[u])
		if(!match[v] || dfs(match[v], tim)) {
			match[v] = u;
			return true;
		}
	return false;
}

int main() {
	n = read(), m = read(), e = read();
	for(int i = 1, u, v; i <= e; i++) {
		u = read() + 1, v = read() + 1;
		E[u].pb(v);
	}
	for(int i = 1; i <= n; i++)
		dfs(i, i);
	for(int i = 1; i <= m; i++)
		if(match[i])	ans[++cnt] = make_pair(match[i], i);
	write(cnt), putchar('\n');
	for(int i = 1; i <= cnt; i++) {
		write(ans[i].first - 1), putchar(' ');
		write(ans[i].second - 1), putchar('\n');
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 81ms
memory: 16708kb

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:

100000
12041 0
72487 1
5283 2
69829 3
42164 4
90712 5
92014 6
59953 7
71269 8
58488 9
96208 10
72327 11
57264 12
60846 13
52381 14
59008 15
50389 16
35924 17
32625 18
21527 19
27578 20
47990 21
90601 22
76846 23
36019 24
21960 25
56983 26
38043 27
92270 28
25033 29
16929 30
23472 31
49575 32
77052 3...

result:

ok OK

Test #2:

score: 0
Accepted
time: 71ms
memory: 14956kb

input:

100000 100000 200000
56815 52516
2576 76201
40377 1757
50463 66496
15833 50879
9828 16330
80692 9962
51095 17590
15870 35191
91301 65509
90774 57492
11890 8966
44786 41895
3386 35478
93470 47452
84803 93635
90745 34876
18201 38717
7472 34257
36580 19532
13248 27524
6441 69869
8821 61870
94536 67713
...

output:

100000
69205 0
60201 1
72021 2
5586 3
28931 4
95944 5
6919 6
54536 7
41523 8
21986 9
82162 10
3261 11
32139 12
82628 13
19581 14
53638 15
86118 16
55752 17
51052 18
29539 19
19938 20
88017 21
72427 22
50563 23
84262 24
96952 25
68293 26
77883 27
15925 28
17312 29
15316 30
64234 31
34238 32
21423 33
...

result:

ok OK

Test #3:

score: 0
Accepted
time: 2ms
memory: 9452kb

input:

4 4 7
1 1
2 2
0 0
3 1
1 2
2 0
3 2

output:

3
0 0
1 1
2 2

result:

ok OK

Test #4:

score: -100
Time Limit Exceeded

input:

100000 100000 199999
25370 25370
85964 85963
415 415
16796 16796
12437 12437
45409 45408
63005 63004
22155 22155
87828 87827
84013 84013
37307 37307
72324 72324
83703 83703
55390 55389
6780 6779
78090 78090
9375 9375
82192 82192
74694 74694
49841 49841
15798 15798
69855 69854
82948 82947
97389 97388...

output:


result: