Data Structures & AlgorithmsModerateCodeforces Div 2 · ICPC regional
A 6 × 6 grid (rows top to bottom, '#' = filled, '.' = empty): ...... / ..#... / .#.### / ....#. / #...## / .#..#.. Two filled cells belong to the same group if they are adjacent horizontally, vertically or diagonally. How many groups are there?
- A. 4
- B. 5
- C. 2
- D. 11
Correct answer: C. 2
Counting groups with 8-directional adjacency gives 2; using only 4 directions merges diagonal pairs and gives 5, so the neighbourhood rule decides the answer.
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
- Undirected weighted graph on vertices A, B, C, D, E, F with edges A–B (9), A–D (7), A–F (7), B–D (5), C–E (9), D–E (5), D–F (7), E–F (3)…
- Undirected weighted graph on vertices A, B, C, D with edges A–C (1), A–D (1), B–C (3), B–D (1), C–D (1). How many distinct minimum…
- Directed weighted graph on vertices A, B, C, D with edges (u→v, w): C→A (2); D→B (1); C→D (7); B→A (5); B→D (5); A→B (8); D→A (3); C→B…
- Rooted tree with root 0 and vertices 0 to 9; the edges are 0–1, 0–2, 1–3, 1–4, 4–5, 3–6, 3–7, 3–8, 4–9 (parent–child). Every edge has…
- Undirected graph on vertices A, B, C, D, E, F, G with weighted edges A–B (4), A–C (4), B–D (1), C–D (5), C–E (5), C–F (8), C–G (1), D–F…
- Undirected weighted graph on vertices A, B, C, D, E with edges A–B (2), A–C (3), B–D (2), B–E (1), C–E (1), D–E (2). An edge is CRITICAL…