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?
- A. 3
- B. 1
- C. 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.
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
- Words ['b', 'c', 'babb', 'accc', 'aaa', 'c'] are inserted in this order into an empty trie with one node per character, shared prefixes…
- Connected undirected weighted graph on vertices A, B, C, D, E with edges A–D (16), A–E (3), B–C (6), B–E (16), C–D (2), C–E (14). What is…
- Words ['cb', 'da', 'abb', 'dbd', 'cd'] (each may be used at most once). A chain is a sequence of these words in which the first letter of…
- Undirected weighted graph on vertices A, B, C, D with edges A–B (2), A–C (3), A–D (3), B–C (3), B–D (2), C–D (3). How many distinct…
- Undirected graph on vertices A, B, C, D, E, F, G with edges A–C (1), A–E (1), A–F (1), B–E (1), B–F (1), B–G (1), C–E (1), D–E (1), E–G…
- Words ['dbd', 'cc', 'bb', 'aca', 'bda', 'ccd'] (each may be used at most once). A chain is a sequence of these words in which the first…