Data Structures & AlgorithmsModerateCodeforces Div 2 · ICPC regional

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

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

Correct answer: C. 4

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic