Data Structures & AlgorithmsVery hardCodeforces Div 2 C · GATE CS

An undirected graph has the vertices F, H, I, K, N, U and the edges U–K, U–H, F–K, F–N, I–H, K–H. 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. 729
  2. B. 96
  3. C. 48
  4. D. 49

Correct answer: C. 48

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic