Data Structures & AlgorithmsModerateCodeforces Div 2 · ICPC regional
Undirected weighted graph on vertices A, B, C, D, E; its edges, in this listed order, are: C–E (9), A–C (8), A–B (5), B–E (3), D–E (2), C–D (9), A–D (2), B–C (7). Run union–find cycle checking over the edges in the LISTED order (an edge is rejected when both its ends are already connected). Which edge is the first one rejected? Answer as the edge with its weight.
- A. C–E (weight 9)
- B. A–B (weight 5)
- C. B–C (weight 7)
- D. B–E (weight 3)
Correct answer: D. B–E (weight 3)
Scanning in the listed order, the first edge that closes a cycle is B–E (weight 3). Scanning in increasing-weight order rejects a different edge first, which is why the processing order matters for identifying which edge is rejected.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Union–find on elements 0 to 7, all starting as singletons, with no path compression. union(x, y): let rx, ry be the roots of x and y; if…
- 2 × 3 sliding puzzle with tiles 1 to 5 and one blank (shown as ). Current board: 4 1 3 / 2 5 . Goal board: 1 2 3 / 4 5 . A move slides a…
- Directed graph on vertices A, B, C, D, E, F with edges D→E, A→B, C→D, F→E, F→C, E→D, A→D, C→A. How many strongly connected components does…
- Undirected simple graph on vertices A, B, C, D, E, F with edges A–C (1), B–D (1), B–E (1), B–F (1), C–D (1), C–E (1), C–F (1), D–E (1)…
- Directed acyclic graph on vertices A, B, C, D, E, F, G (edges go from earlier to later letters) with weights A→B (3), A→D (4), A→E (4)…
- Points A(1,7), B(2,4), C(4,9), D(8,8), E(2,7) in the plane. The cost of joining two points is the Manhattan distance |x1−x2| + |y1−y2|…