시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 512 MB | 0 | 0 | 0 | 0.000% |
London underground consists of many stations, numbered 1 to N, and many lines connecting them, numbered 1 to M. All stations are connected, but some times you have to switch between lines to travel between two stations. This takes S minutes per switch. You can switch between lines L1 and L2 on station Si if both lines stop at station Si. The lines go back and forth all day, with the same distance between stations in both directions. Trains leave in both directions from every station every minute. Alice and Bob are visiting London. They use the underground a lot, but they keep feeling that they aren't always taking the fastest route. Help them find the fastest route between stations A and B.
The first line of the input consists of a single integer, T, the number of test cases.
Each of the following T cases begins with a line consisting of 5 integers S, N, M, A, B, separated by spaces. These numbers give the number of minutes it takes to switch lines, the number of stations, the number of lines, and the start and end stations, respectively.
The next M lines of a test case describe each subway line, and has the following format.
First an integer X, the number of stations on the subway line. Then follows X station specifications, separated by spaces, in the order they appear on the line. Each station specification consists of two integers, where the first number, Sni, is the station number, and the second number, Sti is the number of minutes from the start of the line to that station.
For each test case, output the minimum number of minutes it takes to travel from station A to station B.
3 1 5 1 1 5 5 2 0 1 2 3 5 5 10 4 15 3 4 2 1 4 3 1 0 2 2 3 5 3 2 0 3 10 4 11 1 4 2 1 4 3 1 0 2 2 4 15 3 2 0 3 1 4 2
8 9 5
Contest > IDI Open Contest > IDI Open 2014 L번