Data Structures & AlgorithmsVery hardCodeforces Div 2 D · ICPC regional
An undirected graph on 5 vertices has the edges D–E, D–J, D–T, E–H, E–J, E–T, H–T, J–T. How many simple paths (no repeated vertex) go from D to T? Paths are counted as vertex sequences, so each route is counted once.
- A. 8
- B. 1
- C. 7
- D. 3
Correct answer: C. 7
A DFS that extends the path through unvisited neighbours enumerates every simple route, giving 7. 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
- The directed acyclic graph has the vertices D, F, G, I, J, O, Z and the arcs J→D, I→G, G→F, I→Z, I→D, F→D, G→D. How many distinct directed…
- A connected undirected graph has the vertices D, E, O, P, W and weighted edges (weights in brackets): D–P (3), E–P (19), D–E (8), P–O (5)…
- A bipartite graph has left side P1, P2, P3 and right side Q1, Q2, Q3, Q4, Q5, with edges P3–Q1, P1–Q2, P3–Q2, P3–Q4, P1–Q5, P2–Q4, P1–Q1…
- A grid has 4 rows and 3 columns with these values (top to bottom): 944 176 815 649 A path moves between side-adjacent cells (up, down…
- A tree has vertices with values in brackets: R[-3], G[6], I[7], U[-4], H[3], W[1], P[9], O[-3]. The edges are R–G, G–I, I–U, R–H, R–W…
- An undirected graph has the vertices A, G, Q, Z and the edges Z–A, Z–G, Q–A, Q–G. In how many ways can each vertex be given one of 3…