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), B–D (1), B–E (1), B–G (1), C–D (1), C–F (1), D–E (1), D–F (1), F–G (1) (weights ignored). What is the length, counted in edges, of the shortest cycle with an odd number of edges?

  1. A. 6
  2. B. 7
  3. C. 3
  4. D. 4

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.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic