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)?
- A. 49
- B. 729
- C. 48
- 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.
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
- Each cell of a grid with 3 rows and 5 columns has an arrow: R = right, L = left, U = up, D = down. RURUR LRDLU RDDRD From a cell you may…
- On an 8×8 chessboard, rows and columns are numbered 0 to 7, and squares are written (row, column). A knight moves in the usual L-shape…
- Bellman–Ford is run from source X on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: F→I…
- A tree has the vertices C, E, G, K, N, S, T, V, Z and the edges T–K, K–E, K–V, K–S, S–N, N–C, C–G, G–Z. A centroid is a vertex whose…
- A grid has 3 rows and 3 columns with these values (top to bottom): 787 591 837 A path moves between side-adjacent cells (up, down, left or…
- Consider this function: python def g(n): if n < 3: return n if n % 2 == 0: return g(n - 3) + g(n - 2) return g(n - 1) - 1 What value does…