QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#341039#898. 二分图最大匹配iorit#TL 63ms7668kbC++14954b2024-02-29 15:08:232024-02-29 15:08:24

Judging History

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

  • [2024-02-29 15:08:24]
  • 评测
  • 测评结果:TL
  • 用时:63ms
  • 内存:7668kb
  • [2024-02-29 15:08:23]
  • 提交

answer

#include <bits/stdc++.h>
#define LL long long
#define sl(n) strlen(n)
#define endline puts("")
#define pii pair<int , int>
#define pr_q priority_queue
#define debug puts("DEBUG.")
using namespace std;
const int N = 2e5 + 10;
const int inf = ~0u >> 2;
int n1,n2,m;
int cnt,hd[N];
struct edge
{
	int v,nxt;
}e[N];
void add(int u , int v)
{
	++cnt,e[cnt].v = v;
	e[cnt].nxt = hd[u],hd[u] = cnt;
}
int vis[N],mat[N];
bool dfs(int u , int c)
{
	if(vis[u] == c)
		return 0;
	vis[u] = c;
	for(int i = hd[u];i;i = e[i].nxt)
	{
		int v = e[i].v;
		if( !mat[v] || dfs(mat[v] , c) )
			return mat[v] = u;
	}
	return 0;
}
int main()
{
	cin >> n1 >> n2 >> m;
	for(int i = 1,u,v;i <= m;i++)
		scanf("%d%d" , &u , &v),++u,++v,add(u , v);
	int res = 0;
	for(int i = 1;i <= n1;i++)
		res += dfs(i , i);
	cout << res << endl;
	for(int i = 1;i <= n2;i++)
		if( mat[i] )
			printf("%d %d\n" , mat[i] - 1 , i - 1);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 63ms
memory: 7668kb

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
63893 0
88633 1
96752 2
85610 3
94676 4
76685 5
31448 6
72044 7
70240 8
47175 9
43951 10
20110 11
30466 12
4229 13
46522 14
75223 15
62176 16
26851 17
78013 18
4961 19
85970 20
83385 21
99925 22
9079 23
99774 24
49446 25
97056 26
50528 27
24373 28
33211 29
47321 30
59580 31
78298 32
4755 33
9...

result:

ok OK

Test #2:

score: 0
Accepted
time: 60ms
memory: 7632kb

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
97875 0
94264 1
74429 2
66378 3
74096 4
51747 5
18521 6
42713 7
40688 8
99131 9
51895 10
33489 11
99689 12
77565 13
47931 14
25562 15
25766 16
55887 17
2119 18
45605 19
11619 20
51396 21
81044 22
91839 23
83277 24
87787 25
9579 26
95681 27
76389 28
75933 29
50341 30
81760 31
65030 32
2286 33
...

result:

ok OK

Test #3:

score: 0
Accepted
time: 1ms
memory: 3888kb

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: