from teflib import tgraph
def minimum_vertex_cover(bigraph):
def dfs_rec(u, is_mvc):
is_mvc[u] = False
for v in bigraph[u]:
if not is_mvc[v]:
is_mvc[v] = True
if (next_u := matched_node[v]) is not None and is_mvc[next_u]:
dfs_rec(next_u, is_mvc)
matching = tgraph.bipartite_matching(bigraph)
matched_node = [None] * len(bigraph)
for u, v in matching.items():
matched_node[v] = u
is_mvc = [bool(edges) for edges in bigraph]
for u, edges in enumerate(bigraph):
if edges and u not in matching:
dfs_rec(u, is_mvc)
return [u for u, u_is_mvc in enumerate(is_mvc) if u_is_mvc]