Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D

Problem: In a graph with vertices 0–6, each edge has weight 0 or 1. Edges: 0-1 (0), 0-2 (1), 1-3 (1), 2-3 (0), 3-4 (1), 4-5 (0), 2-6 (1), 5-6 (1). What is the minimum total weight of a path from vertex 0 to vertex 6 (edges may be used in either direction)?

  1. A. 3
  2. B. 1
  3. C. 2
  4. D. 4

Correct answer: C. 2

A 0-1 BFS uses a deque: zero-weight edges go to the front and weight-one edges to the back. Treating every edge as weight one gives the BFS hop count, which is a different and larger number here.

More Coding Interview Problems questions

Exams that ask this topic