Data Structures & AlgorithmsHardCodeforces Div 2 C · GATE CS
A directed acyclic graph has the vertices F, N, R, S, T, U, V, X and the directed edges R→V, U→S, S→X, F→X, N→V, R→S, U→F, F→N, R→F, R→T, S→F. How many edges does a longest directed path in this graph contain?
- A. 2
- B. 5
- C. 7
- D. 4
Correct answer: D. 4
Take dp[x] = 1 + max(dp[y]) over arcs y→x, with dp = 0 for sources; the largest dp value is 4 edges. Following the first listed out-arc at each step gives only 2, and counting vertices instead of edges gives 5.
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 graph has the vertices B, E, G, I, J, K, O, P and the edges I–J, I–O, J–E, J–G, J–P, E–K, E–B, G–P, G–B, G–O, K–P, K–B. What…
- An undirected connected graph on the vertices E, I, L, Y, Z has the edges Y–I, Y–Z, E–Y, L–Z, E–Z, E–I. How many spanning trees does it…
- A bipartite graph has left side P1, P2, P3, P4 and right side Q1, Q2, Q3, Q4, with edges P2–Q3, P2–Q1, P2–Q2, P3–Q4, P1–Q3, P3–Q3. What is…
- Bellman–Ford is run from source T on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: P→Y…
- A directed graph has the vertices A, G, N, S, T, Y, Z and the arcs N→A, N→S, T→N, T→Z, T→Y, T→S, A→N, A→Y, Z→N, Z→T, Z→Y, Z→S, G→N, G→A…
- A tree has the vertices C, I, N, P, T, U, X, Y, Z and the edges N–Z, N–Y, N–U, Y–I, I–X, N–C, Y–T, T–P. What is the minimum number of…