Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 B

An undirected graph has the vertices D, N, P, W, Z and the edges W–D, W–P, W–Z, D–N, N–Z. 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. 72
  2. B. 48
  3. C. 243
  4. D. 36

Correct answer: D. 36

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic