Data Structures & AlgorithmsHardCodeforces Div 2 · ICPC regional
Undirected graph on vertices A, B, C, D, E, F, G with edges A–B (1), A–C (1), B–C (1), B–D (1), B–E (1), B–F (1), C–E (1), D–E (1), E–G (1), F–G (1) (weights ignored). Vertices are coloured in the order A, B, C, … each with the smallest-numbered colour (0, 1, 2, …) not used by an already coloured neighbour. How many colours does this greedy colouring use?
- A. 4
- B. 3
- C. 6
- D. 5
Correct answer: A. 4
Greedy colouring in this vertex order uses 4 colours, while the chromatic number is 3. Confusing the order-dependent greedy result with the optimal value is the mistake.
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
- Words ['dd', 'bb', 'bcd', 'bcc', 'cad', 'baa'] (each may be used at most once). A chain is a sequence of these words in which the first…
- Tree with vertices 0 to 8, root 0, edges 0–1, 1–2, 2–3, 1–4, 4–5, 1–6, 3–7, 6–8 (parent–child). Vertex weights (vertex:weight) 0:18, 1:16…
- Weighted tree on vertices 0 to 7 with edges 0–1 (8), 0–2 (4), 0–3 (1), 1–4 (2), 1–5 (2), 5–6 (4), 1–7 (7). What is the largest possible…
- Tree with vertices 0 to 6, root 0, edges 0–1, 0–2, 1–3, 3–4, 4–5, 2–6 (parent–child). Vertex weights (vertex:weight) 0:13, 1:5, 2:12…
- Distinct words ['baab', 'bcb', 'cbaa', 'ccba', 'bbaa', 'ab', 'aac'] are inserted into an empty trie (one node per character, shared…
- Connected undirected graph on vertices A, B, C, D, E, F, G, H with edges A–B (1), A–E (1), A–G (1), C–F (1), C–G (1), D–F (1), D–H (1)…