Data Structures & AlgorithmsHardCodeforces Div 2 · ICPC regional
Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–D (1), B–C (1), B–E (1), B–F (1), B–G (1), C–D (1), C–F (1), C–G (1), D–F (1), E–G (1) (weights ignored). What is the length, counted in edges, of the shortest cycle with an odd number of edges?
- A. 7
- B. 4
- C. 3
- D. 6
Correct answer: C. 3
Enumerating simple cycles gives shortest odd length 3; the shortest even cycle is 4 and the parity condition is what separates them.
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
- Undirected weighted graph on vertices A, B, C, D, E, F with edges A–B (4), A–C (5), A–D (6), C–D (5), C–E (7), D–E (5), D–F (5), E–F (6)…
- Array [13, 15, 17, 14, 6, 23, 3] is turned into a min-heap in place with bottom-up heapify: for i from ⌊n/2⌋−1 down to 0, sift the element…
- Keys [12, 24, 3, 18, 30, 33, 7, 16, 4] are inserted, in this order, into an empty AVL tree using the standard rebalancing (left, right…
- Distinct keys [13, 24, 18, 4, 20] are inserted, in the order given by the sequence [18, 20, 4, 24, 13], into an empty binary search tree…
- Distinct words ['baa', 'c', 'b', 'bac', 'bba', 'cbbc'] are inserted into an empty trie (one node per character, shared prefixes sharing…
- Directed graph on vertices A, B, C, D, E, F with edges E→D, A→D, F→C, E→C, A→E, B→C, A→F, D→A. How many strongly connected components does…