Data Structures & AlgorithmsModerateCodeforces Div 2 · ICPC regional
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 (6), E–G (8), F–G (8). Keep only the edges of weight at most 5 (discard the others). How many connected components does the remaining graph have?
- A. 3
- B. 1
- C. 2
- D. 7
Correct answer: C. 2
Only edges of weight ≤ 5 survive; the result has 2 components. Subtracting the number of kept edges from n ignores the edges that close cycles and gives 1.
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 with edges A–B (2), A–C (3), B–D (2), B–E (1), C–E (1), D–E (2). An edge is CRITICAL…
- Rooted tree with root 0 and vertices 0 to 9; the edges are 0–1, 1–2, 1–3, 3–4, 2–5, 5–6, 6–7, 3–8, 3–9 (parent–child). Every edge has…
- Coins of denominations [12, 10, 2] are available in unlimited quantity. What is the minimum number of coins needed to pay exactly 20?…
- Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–D (1), A–F (1), A–G (1), B–G (1), C–F (1), C–G (1), D–E (1), D–F (1)…
- Array A = [26, 14, 21, 19, 25, 20] (all values below 32). What is the maximum of A[i] XOR A[j] over all index pairs with 0 ≤ i < j < 6?
- Keys are inserted in the order 12 48 72 44 38 26 into an empty binary search tree. Then the key 48 (which has two children) is deleted by…