#P2754. [CTSC1999] 家园 / 星际转移问题
[CTSC1999] 家园 / 星际转移问题
Description
Due to humanity’s consumption of natural resources, people realized that around the year 2300, Earth would no longer be habitable. Therefore, new green zones were established on the Moon to enable migration when needed. Unexpectedly, in the winter of 2177, due to unknown reasons, Earth’s environment suffered a chain collapse, and humanity must migrate to the Moon as quickly as possible.
There are space stations located between Earth and the Moon, and there are public transport spacecraft shuttling back and forth among them. Each space station can hold an unlimited number of people, but each spacecraft has limited capacity: the -th spacecraft can carry people. Each spacecraft periodically stops at a sequence of stations; for example, means the spacecraft will cyclically stop at stations . It takes time for a spacecraft to travel from any station to any other station. People can board or disembark only when a spacecraft is docked at a station (or the Moon, or Earth).
Initially, all people are on Earth, and all spacecraft are at their initial stops. Design an algorithm to find a transportation plan that transfers all people to the Moon in the shortest possible time.
Input Format
The first line contains three integers separated by spaces, representing the number of space stations , the number of spacecraft , and the number of people on Earth .
Lines through each describe one spacecraft. On line , the first integer is the capacity of the -th spacecraft. Then an integer follows, representing the number of stops of the -th spacecraft. After that are integers, in order, representing the indices of the stops , where the space stations are numbered from to , Earth is indexed as , and the Moon as .
Output Format
Output a single integer representing the shortest time needed to transfer all people to the Moon. If there is no solution, output .
2 2 1
1 3 0 1 2
1 3 1 2 -1
5
Hint
Constraints
For of the testdata, it is guaranteed that:
- .
- .
- .
- .
- .
Translated by ChatGPT 5
京公网安备 11011102002149号