-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcses_1696.cpp
More file actions
56 lines (51 loc) · 944 Bytes
/
cses_1696.cpp
File metadata and controls
56 lines (51 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <bits/extc++.h>
using namespace std;
int n, m, k;
vector<vector<int>> G;
vector<int> match;
vector<bool> visited;
bool dfs(int u)
{
for (int v : G[u])
{
if (visited[v])
continue;
visited[v] = true;
if (!match[v] || dfs(match[v]))
{
match[v] = u;
return true;
}
}
return false;
}
int konig()
{
match.assign(n + 1, 0);
int ans = 0;
for (int i = 1; i <= m; i++)
{
visited.assign(n + 1, false);
if (dfs(i))
ans++;
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> k;
G.resize(m + 1);
while (k--)
{
int u, v;
cin >> u >> v;
G[v].emplace_back(u);
}
cout << konig() << '\n';
for (int i = 1; i <= n; i++)
if (match[i] != 0)
cout << i << ' ' << match[i] << '\n';
return 0;
}