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–E (1), A–F (1), C–E (1), D–E (1), D–G (1), E–F (1), F–G (1) (weights ignored). What is the length, counted in edges, of the shortest cycle with an odd number of edges?
- A. 5
- B. 3
- C. 7
- D. 4
Correct answer: B. 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
- Distinct keys [25, 10, 8, 14, 19] are inserted, in the order given by the sequence [19, 8, 14, 10, 25], into an empty binary search tree…
- Undirected weighted graph on vertices A, B, C, D, E with edges A–B (3), A–C (3), A–D (1), B–E (1), C–D (2), C–E (3). How many distinct…
- Distinct keys [3, 21, 7, 19, 24] are inserted, in the order given by the sequence [7, 21, 19, 24, 3], into an empty binary search tree…
- Connected undirected weighted graph on vertices A, B, C, D with edges A–B (3), A–C (1), A–D (4), B–C (1), B–D (2), C–D (6). Among all…
- Array A = [2, 24, 11, 16, 9, 22, 23, 10, 19]. How many index pairs i < j satisfy (A[i] XOR A[j]) < 25? (A trie with subtree counts answers…
- Strings a = "ccbab" and b = "bbbcaa". The edit distance allows insert, delete and substitute, each costing 1 (the standard Levenshtein…