Data Structures & AlgorithmsModerateCodeforces Div 2 D · ICPC regional

An undirected graph has the vertices A, B, D, P, R, Y and the edges P–D, P–B, P–R, D–A, D–Y, B–Y, A–R, R–Y. 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. 49
  2. B. 729
  3. C. 48
  4. D. 96

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