-
Notifications
You must be signed in to change notification settings - Fork 185
/
Copy path1695.cc
52 lines (49 loc) · 1022 Bytes
/
1695.cc
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
// https://cses.fi/problemset/task/1695/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 500;
int n;
ll g[N][N], c, f;
vector<bool> s;
ll dfs(int i) {
s[i] = 1;
if (i == n - 1) {
f++;
return 1;
}
for (int j = 0; j < n; j++)
if (!s[j] && g[i][j])
if (dfs(j)) {
g[i][j]--;
g[j][i]++;
return 1;
}
return 0;
}
int main() {
cin.tie(0), ios::sync_with_stdio(0);
int m, a, b;
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> a >> b;
a--, b--;
g[a][b] = g[b][a] = 1;
}
s = vector<bool>(n);
while (dfs(0)) fill(s.begin(), s.end(), 0);
cout << f << '\n';
fill(s.begin(), s.end(), 0);
s[0] = 1;
queue<int> q;
q.push(0);
while (!q.empty()) {
a = q.front();
q.pop();
for (int b = 0; b < n; b++)
if (!s[b] && g[a][b]) s[b] = 1, q.push(b);
}
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (s[i] && !s[j] && g[j][i]) cout << i + 1 << ' ' << j + 1 << '\n';
}