Problem list
Log in
#usaco0171 · USACO 2014-2015 January Silver

Cow Routing (Silver)

Bronze II 2.0 s 256 MB

(Same setup as the Bronze Cow Routing problems.) Air Bovinia owns N planes (1 <= N <= 1000), each flying on a route of two or more cities. Bessie may board at any city along a route and disembark at any later city, paying the route's full cost each time she uses any part of it (using a route multiple times costs for each use).

Bessie wants the cheapest way to travel from city A to city B, and also the smallest number of individual flights she must take to achieve this minimum cost.

Input

Line 1: A, B, and N, separated by spaces.

The next 2N lines describe the available routes, two lines per route. The first line contains the cost of the route (1..1,000,000,000) and the number of cities along the route (1..100). The second line lists the cities in order. Each city is an integer in the range 1..1000. The total cost may exceed a 32-bit integer, so use 64-bit integers.

Output

The minimum cost of an itinerary from city A to city B, as well as the minimum number of individual flights required to achieve this minimum cost. If there is no solution, output "-1 -1".

Example 1

Input
3 4 3
3 5
1 2 3 4 5
2 3
3 5 4
1 2
1 5
Output
2 2
Source
USACO 2014-2015 January Silver
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 3 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code