init
This commit is contained in:
commit
851751ea87
82 changed files with 2093 additions and 0 deletions
37
AB.py
Normal file
37
AB.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import sys
|
||||
|
||||
sys.setrecursionlimit(4000)
|
||||
|
||||
data = sys.stdin.read().split()
|
||||
|
||||
num_v = int(data[0])
|
||||
num_e = int(data[1])
|
||||
|
||||
adj = [[] for _ in range(num_v + 1)]
|
||||
cursor = 2
|
||||
|
||||
for _ in range(num_e):
|
||||
src = int(data[cursor])
|
||||
dst = int(data[cursor + 1])
|
||||
cursor += 2
|
||||
adj[src].append(dst)
|
||||
|
||||
pairs = [0] * (num_v + 1)
|
||||
|
||||
def find_match(node):
|
||||
if visited[node]:
|
||||
return False
|
||||
visited[node] = True
|
||||
for nxt in adj[node]:
|
||||
if pairs[nxt] == 0 or find_match(pairs[nxt]):
|
||||
pairs[nxt] = node
|
||||
return True
|
||||
return False
|
||||
|
||||
total_matches = 0
|
||||
for start_node in range(1, num_v + 1):
|
||||
visited = [False] * (num_v + 1)
|
||||
if find_match(start_node):
|
||||
total_matches += 1
|
||||
|
||||
print(num_v - total_matches)
|
||||
Loading…
Add table
Add a link
Reference in a new issue