Data Structures & AlgorithmsModerateCodeforces Div 2 · ICPC regional
Undirected weighted graph on vertices A, B, C, D, E, F; its edges, in this listed order, are: C–F (2), B–D (2), D–E (7), B–C (9), D–F (2), C–D (7), A–F (7), C–E (8). 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–F (weight 2)
- B. D–F (weight 2)
- C. C–D (weight 7)
- D. C–E (weight 8)
Correct answer: B. D–F (weight 2)
Scanning in the listed order, the first edge that closes a cycle is D–F (weight 2). 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
- Directed weighted graph on vertices A, B, C, D, E with edges (u→v, w): C→A (8); D→E (2); B→A (9); E→D (1); B→D (1); A→E (1); E→A (9); A→B…
- Undirected weighted graph on vertices A, B, C, D, E, F with edges A–B (1), A–C (3), B–C (7), B–D (5), B–E (7), B–F (7), C–F (2), D–E (1)…
- Undirected graph on vertices A, B, C, D, E, F, G with weighted edges A–C (7), A–D (7), B–C (4), B–F (9), B–G (5), C–F (5), D–F (1), E–F…
- Keys are inserted in the order 12 31 77 11 65 57 into an empty binary search tree. Then the key 12 (which has two children) is deleted by…
- Distinct words ['aa', 'ab', 'bb', 'ca', 'aab'] are inserted into an empty trie (one node per character, shared prefixes share nodes, and a…
- Keys are inserted in the order 11 88 20 15 45 into an empty binary search tree. Then the key 20 (which has two children) is deleted by…