Data Structures & AlgorithmsVery hardCodeforces Div 2 C · GATE CS
An undirected graph has the vertices F, H, I, K, N, U and the edges U–K, U–H, F–K, F–N, I–H, K–H. 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. 729
- B. 96
- C. 48
- 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 -729.
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 connected graph on the vertices F, G, I, Z has the edges Z–G, Z–I, F–Z, F–I, F–G, G–I. How many spanning trees does it have?…
- A pile holds p stones. In one move a player removes exactly s stones, where s is one of {4, 5, 6} and s ≤ the pile size. The player who…
- A directed graph has the vertices E, H, L, M, Q, U and the arcs H→U, M→Q, U→H, U→Q, E→H, E→M, L→H. How many strongly connected components…
- A directed graph has the vertices C, I, L, R, U and the arcs I→U, I→C, I→L, R→I, R→U, R→C, R→L, U→C, C→I, C→L, L→U. Count the directed…
- Grid with 3 rows and 4 columns (top to bottom). A cell marked G is a gate; '.' is a normal cell: .G.G G.G. .... Each step, which is a move…
- Starting from the integer 6, one operation either adds 1, subtracts 1, or doubles the current value. Values may be any non-negative…