Data Structures & AlgorithmsVery hardICPC regional · bipartite matching
Problem: What is the maximum matching size in the bipartite graph with left vertices {0,1,2}, right vertices {0,1,2} and edges (0,0), (0,1), (1,0), (2,1)? Run Kuhn's augmenting-path code.
Problem: What is the maximum matching size in the bipartite graph with left vertices {0,1,2}, right vertices {0,1,2} and edges (0,0), (0,1), (1,0), (2,1)? Run Kuhn's augmenting-path code.
adj = {0: [0, 1], 1: [0], 2: [1]}
match_r = {}
def try_kuhn(u, seen):
for v in adj[u]:
if v in seen:
continue
seen.add(v)
if v not in match_r or try_kuhn(match_r[v], seen):
match_r[v] = u
return True
return False
res = 0
for u in adj:
if try_kuhn(u, set()):
res += 1
print(res)What is printed?- A. 3
- B. 1
- C. 0
- D. 2
Correct answer: D. 2
Vertex 1 can only take right 0 and vertex 2 can only take right 1, so at most two can be matched and two are achievable.
More Coding Interview Problems questions
- Problem: How many integers x in [1, 100] satisfy x^2 ≡ 1 (mod 8)? Run the code. python print(sum(1 for x in range(1, 101) if (x x) % 8 ==…
- Problem: What is the smallest positive integer x with x ≡ 1 (mod 4) and x ≡ 2 (mod 5)? Run the code. python print(next(x for x in range(1…
- Problem: How many integers in [1, 100] have non-decreasing decimal digits (for example 1245 or 3399, but 2 digits only here)? Run the…
- Problem: What is the spiral (clockwise from the top-left) traversal of the matrix [[1,2,3],[4,5,6],[7,8,9]]? Print the list produced by…
- Problem: How many swaps does insertion sort perform on [3, 2, 1]? Count the shifts in the code. python a = [3, 2, 1] swaps = 0 for i in…
- Problem: What is the minimum number of intervals from [[1,4],[3,7],[6,10],[9,10]] needed to cover the segment [1, 10]? Run the greedy…