#P3115. Air Bovinia Routes
Air Bovinia Routes
Air Bovinia Routes
Bessie the cow wants to escape the cold winter on her farm by flying to a warmer destination. Unfortunately, only one airline, Air Bovinia, sells tickets to cows and its ticketing system is quite unusual.
Air Bovinia operates \( N \) planes (where \(1 \le N \le 1000\)). Each plane flies a specific route consisting of two or more cities, with no city appearing more than once in a route. For a given route, Bessie can board at any city along the route and disembark at any later city. She does not have to board at the first city or disembark at the last city. However, if Bessie uses any portion of a route, she must pay the full cost associated with that route, regardless of how many flights she takes within it. Moreover, if she leaves a route and later uses it again (even if from a different city), she must pay for it each time.
Bessie wants to determine the cheapest way to travel from her farm in city \(A\) to her tropical destination in city \(B\). In the event that more than one travel plan yields the same minimum cost, she would like to minimize the number of individual flights taken.
Your task is to compute two values:
- The minimum total cost to travel from \(A\) to \(B\).
- The minimum number of individual flights required to achieve that cost.
If there is no possible way to travel from \(A\) to \(B\), output -1 -1
.
inputFormat
The first line contains three integers: \(N\), \(A\), and \(B\), where \(N\) denotes the number of routes (\(1\le N\le 1000\)), and \(A\) and \(B\) are the starting and destination cities, respectively.
Each of the following \(N\) lines describes a route. The line starts with two integers: the cost of using the route and \(L\) (the number of cities in the route, with \(L\ge 2\)). This is followed by \(L\) distinct integers representing the cities visited by the route in order.
outputFormat
Output two integers separated by a space: the minimum total cost and the minimum number of flights taken. If it is impossible to travel from city \(A\) to city \(B\), output -1 -1
.
sample
3 1 8
3 4 1 5 2 8
4 3 1 4 8
5 5 1 3 6 4 8
3 3