Data Structures & AlgorithmsHardCodeforces Div 2 · ICPC regional
Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–B (1), A–D (1), A–F (1), B–C (1), B–D (1), B–F (1), C–E (1), D–E (1), F–G (1) (weights ignored). What is the length, counted in edges, of the shortest cycle with an odd number of edges?
- A. 6
- B. 4
- C. 3
- D. 7
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
- Keys are inserted in the order 48 55 26 32 38 into an empty binary search tree. Then the key 48 (which has two children) is deleted by…
- Words ['b', 'abbb', 'b', 'ca', 'b', 'bac'] are inserted in this order into an empty trie with one node per character, shared prefixes…
- Directed weighted graph on vertices A, B, C, D, E, F with edges listed in this exact order: F→D (3); F→B (3); D→E (1); D→B (2); A→C (7)…
- Tree with vertices 0 to 7, root 0, edges 0–1, 1–2, 0–3, 3–4, 2–5, 5–6, 1–7 (parent–child). Vertex weights (vertex:weight) 0:10, 1:14…
- Distinct keys [10, 21, 12, 26, 19] are inserted, in the order given by the sequence [12, 21, 19, 10, 26], into an empty binary search…
- A chain of 5 matrices M1 to M5 has dimensions given by the sequence p = [20, 17, 5, 11, 19, 20], where Mi has size p[i−1] × p[i]…