Data Structures & AlgorithmsModerateGATE CS · ICPC regional

An undirected graph has the vertices A, B, F, I, J, P and the edges I–A, I–J, I–B, A–P, A–F, J–P, J–F, P–B. 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 -1215.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic