Data Structures & AlgorithmsHardCodeforces Div 2 C · GATE CS
An undirected graph has the vertices A, G, Q, Z and the edges Z–A, Z–G, Q–A, Q–G. 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. 18
- B. 24
- C. 36
- D. 81
Correct answer: A. 18
Count the proper 3-colourings by backtracking over the vertices; there are 18. Forgetting the edges gives 81, and subtracting each edge's monochromatic colourings once (no overlaps) gives -27.
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
- A directed acyclic graph has the vertices E, N, O, S, U, V, Z and the edges Z→S, N→O, U→V, U→N, U→O, E→V, E→S. A topological order lists…
- An undirected graph on 6 vertices has the edges I–S, I–F, I–W, I–Q, I–K, S–F, S–K, F–K. How many simple paths (no repeated vertex) go from…
- An undirected connected graph on 6 vertices has the edges (weights in brackets, all distinct): X–Z (14), X–S (12), V–Z (30), S–Z (4), V–S…
- Consider this function: python def g(n): if n < 2: return n if n % 2 == 0: return g(n - 3) + g(n - 2) return g(n - 3) - 1 What value does…
- A connected undirected graph has the vertices F, H, I, M, O, V and the edges F–M, F–I, F–O, M–V, M–H, H–I. How many bridges does it have…
- A counter starts at 1. Each step, you may add 1, add 2, or double the counter. Each step must stay at or below 10. Two sequences of steps…