Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2 B

An undirected graph has the vertices D, F, J, L, N, Y and the edges D–Y, Y–N, Y–J, N–F, F–J, J–L. 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. 144
  4. D. 72

Correct answer: D. 72

Count the proper 3-colourings by backtracking over the vertices; there are 72. 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