Data Structures & AlgorithmsHardCodeforces Div 2 D · ICPC regional
An undirected graph on 6 vertices has the edges I–S, I–F, I–W, I–Q, I–K, S–F, S–K, F–K. How many simple paths (no repeated vertex) go from I to K? Paths are counted as vertex sequences, so each route is counted once.
- A. 8
- B. 1
- C. 5
- D. 2
Correct answer: C. 5
A DFS that extends the path through unvisited neighbours enumerates every simple route, giving 5. Counting only the shortest routes gives 1, which is a much smaller set.
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
- An undirected connected graph on 6 vertices has the edges (weights in brackets, all distinct): X–Z (14), X–S (12), V–Z (30), S–Z (4), V–S…
- Consider this function: python def g(n): if n < 2: return n if n % 2 == 0: return g(n - 3) + g(n - 2) return g(n - 3) - 1 What value does…
- A connected undirected graph has the vertices F, H, I, M, O, V and the edges F–M, F–I, F–O, M–V, M–H, H–I. How many bridges does it have…
- A counter starts at 1. Each step, you may add 1, add 2, or double the counter. Each step must stay at or below 10. Two sequences of steps…
- An undirected graph has the vertices C, G, I, K, N, W, Y and the edges C–Y, C–I, C–W, C–K, Y–I, Y–W, Y–K, N–I, N–W, G–K, I–K, W–K. What is…
- A directed weighted graph has the arcs u→v (weight): B→U (10), B→S (15), O→U (1), O→S (9), O→P (7), O→L (11), U→O (8), U→S (3), S→L (2)…