Data Structures & AlgorithmsModerateCodeforces Div 2 · ICPC regional
Undirected graph on vertices A, B, C, D, E, F, G with weighted edges A–C (5), A–E (5), A–F (4), B–D (6), B–E (1), B–F (6), B–G (8), C–G (2), D–E (1), D–G (3). Keep only the edges of weight at most 5 (discard the others). How many connected components does the remaining graph have?
- A. 1
- B. 0
- C. 7
- D. 4
Correct answer: A. 1
Only edges of weight ≤ 5 survive; the result has 1 components. Subtracting the number of kept edges from n ignores the edges that close cycles and gives 0.
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
- Rooted tree with root 0 and vertices 0 to 8; the edges are 0–1, 0–2, 2–3, 2–4, 4–5, 1–6, 1–7, 3–8 (parent–child). Every edge has length 1…
- Keys are inserted in the order 40 89 17 61 57 into an empty binary search tree. Then the key 40 (which has two children) is deleted by…
- Array A = [11, 11, 2, 3, 14, 14]. Over all non-empty contiguous subarrays, what is the maximum value of the XOR of the elements in the…
- Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–C (1), A–D (1), A–F (1), B–C (1), B–D (1), B–F (1), C–F (1), D–F (1)…
- Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–D (1), B–C (1), B–E (1), B–F (1), B–G (1), C–D (1), C–F (1), C–G (1)…
- Undirected weighted graph on vertices A, B, C, D, E, F with edges A–B (4), A–C (5), A–D (6), C–D (5), C–E (7), D–E (5), D–F (5), E–F (6)…