PO Archiving
Time limit1sMemory limit1024 MB
Choose a set of solutions to store and directed diffs to save so every solution is reconstructable, minimizing total bytes.
- Level
Medium7 of 10
- Topics
- Graph, Minimum spanning tree, Greedy, Implementation
- Solved
- No attempts yet
Problem
After every competition, the Programming Olympiad archives the participants' solutions forever. Most of the solutions submitted during a competition are quite similar, though. A contestant who fixes a bug might only change a single line in a solution. In these cases it is unnecessary to save both the original solution and the changed solution. Instead we can save one of the solutions along with the changes that were made between the two solutions. This can also happen in several steps, so that one saves a solution , then saves the changes between and another solution , and finally the changes between and a third solution .
In total solutions were submitted during a competition, with sizes bytes. If the -th solution is either saved or can be reconstructed, then the -th solution can be reconstructed if the changes that are bytes large are saved.
In most test case groups the diff sizes will be symmetric, i.e. (similar to ordinary Unix diff files). For the last group, however, we consider more general diffs where this need not hold. For example, we can imagine that the difference between the strings abaabbaaa and aaaaaa is saved as "remove all b" in one direction, and "insert b at positions 2, 5, 6" in the other, where the latter change requires more space to save than the former.
What is the minimum amount of data (in bytes) that must be saved in order for all solutions to be reconstructable?
Input
The first line contains the integer . The next line contains the integers . The next lines each contain integers. The -th of these lines contains the numbers . for all .
Output
Print a single number: the minimum amount of data that must be saved, in bytes.