Data Structures & AlgorithmsHardCodeforces Div 2 · ICPC regional
Directed acyclic graph on vertices A, B, C, D, E, F, G (every edge goes from a smaller to a larger letter) with weighted edges A→C (9), A→E (1), A→G (1), B→G (4), C→D (6), C→F (6), C→G (4), D→F (2), D→G (3), E→F (8). What is the largest total weight of any directed path (one or more edges) in this graph?
- A. 9
- B. 18
- C. 44
- D. 3
Correct answer: B. 18
A DP over vertices in topological order gives a heaviest path of weight 18. Counting the edges of that path, or summing every weight, gives other numbers.
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
- Undirected weighted graph on vertices A, B, C, D with edges A–B (3), A–C (2), A–D (1), B–C (2), B–D (2), C–D (1). How many distinct…
- Keys [2, 42, 28, 49, 8, 35] are inserted, in this order, into an empty AVL tree using the standard rebalancing (left, right, left–right…
- Distinct words ['a', 'cbb', 'c', 'b'] are inserted into an empty trie (one node per character, shared prefixes share nodes, and a root)…
- Directed weighted graph on vertices A, B, C, D, E with edges listed in this exact order: A→B (6); E→A (4); C→D (5); B→E (5); B→C (4); A→D…
- Distinct words ['ca', 'b', 'bac', 'a', 'c', 'bbbb'] are inserted into an empty trie (one node per character, shared prefixes sharing…
- A chain of 6 matrices M1 to M6 has dimensions given by the sequence p = [16, 18, 7, 19, 14, 15, 7], where Mi has size p[i−1] × p[i]…