Data Structures & AlgorithmsModerateCodeforces Div 2 C · GATE CS
An undirected graph has the vertices D, E, H, J, M, P and the edges P–E, P–H, P–J, E–H, E–D, M–J, M–D. 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)?
- A. 60
- B. 30
- C. 729
- D. 96
Correct answer: B. 30
Count the proper 3-colourings by backtracking over the vertices; there are 30. Forgetting the edges gives 729, and subtracting each edge's monochromatic colourings once (no overlaps) gives -972.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- 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…
- A directed acyclic graph has the vertices A, E, K, L, M, N and the directed edges L→A, K→N, E→K, L→E, M→N, L→K, M→E, E→N, L→N. How many…
- A directed weighted graph has the arcs u→v (weight): J→I (6), I→J (1), I→R (3), I→B (5), Q→I (2), Q→E (4), R→J (12), R→I (10), R→Q (2)…
- A pile holds p stones. In one move a player removes exactly s stones, where s is one of {1, 5, 6} and s ≤ the pile size. The player who…
- A tree has vertices with weights in brackets: W[13], K[12], O[13], C[2], Z[8], F[8], P[5], Y[15]. The edges are W–K, W–O, O–C, C–Z, O–F…
- Starting from the integer 13, one operation either adds 1, subtracts 1, or doubles the current value. Values may be any non-negative…