Data Structures & AlgorithmsModerateCodeforces Div 2 D · ICPC regional

An undirected graph has the vertices C, E, L, M, T and the edges L–E, L–T, M–C, E–C, C–T. In how many ways can each vertex be given one of 3 colours (colours are labelled, and no two adjacent vertices may share a colour)?

  1. A. 72
  2. B. 48
  3. C. 36
  4. D. 243

Correct answer: C. 36

Count the proper 3-colourings by backtracking over the vertices; there are 36. Forgetting the edges gives 243, and subtracting each edge's monochromatic colourings once (no overlaps) gives -162.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic