Editorial for TLE '17 Contest 1 P6 - Investment
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
First, break the graph into maximal biconnected components. You can do this by using Tarjan's articulation point algorithm. These are the only companies that you should consider investing into.
For each pair of connected companies, create an edge between them. However, this will create up to
Once we have done this, the graph will be like a tree, but with hyperedges. When starting from a component, scan through all its planets to find the descendent "subtrees". Be very careful to not traverse back up a tree, or sideways as that can lead to an incorrect answer.
For each component, have a dp state of
- You use the current component, and are free to choose any of the descendent components. However, if you use any component directly descendant from the current, you must subtract the profit of the shared planet to avoid double counting.
- You don't use the current component, and don't use any directly descendent components. This is the standard knapsack tree dp problem.
- You don't use the current component, and must use at least
directly descendent component. To solve this, you must create inplace dp states and perform knapsack on it.
When you are done, you should have the solution for using all
To account for "holding on to investments", simply get the value of:
Time Complexity:
Comments