-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2316.py
More file actions
31 lines (30 loc) · 725 Bytes
/
Copy path2316.py
File metadata and controls
31 lines (30 loc) · 725 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
import sys
rl = sys.stdin.readline
N, P = map(int, rl().split())
MN = N*2+2
c = [[0 for _ in range(MN)] for _ in range(MN)]
for i in range(2,MN,2): c[i][i+1] = 1
c[2][3], c[4][5] = 1e9, 1e9
for _ in range(P):
a, b = map(int, rl().split())
c[a*2+1][b*2], c[b*2+1][a*2] = 1, 1
f = [[0 for _ in range(MN)] for _ in range(MN)]
ans = 0
while True:
q = [2]
p = [-1 for _ in range(MN)]
p[2] = 2
while q:
now = q.pop()
for i in range(1,MN):
if c[now][i] - f[now][i]>0 and p[i] == -1:
q.append(i)
p[i] = now
if p[5] == -1: break
x = 5
while x != 2:
f[x][p[x]] -= 1
f[p[x]][x] += 1
x = p[x]
ans += 1
print(ans)