Data Structures & AlgorithmsModerateCodeforces Div 2 · ICPC regional

Undirected graph on vertices A, B, C, D, E, F with weighted edges A–B (4), A–C (7), A–E (3), B–C (6), B–E (4), B–F (2), C–D (7), C–F (2). Keep only the edges of weight at most 4 (discard the others). How many connected components does the remaining graph have?

  1. A. 6
  2. B. 2
  3. C. 1
  4. D. 3

Correct answer: B. 2

Only edges of weight ≤ 4 survive; the result has 2 components. Subtracting the number of kept edges from n ignores the edges that close cycles and gives 1.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic