Data Structures & AlgorithmsModerateGATE CS · ICPC regional

An undirected graph has the vertices C, P, T, X and the edges T–P, C–P, C–X, P–X. 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. 24
  2. B. 81
  3. C. 12
  4. D. 13

Correct answer: C. 12

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic