Friends with different speeds start from given cities and must meet in one city, so minimize the worst arrival time over all cities.
Medium4Shortest pathGraphInterviewNo attempts yetTime limit5sMemory limit512 MBFriends who live in different cities want to gather in one place. The roads are tangled and the friends live far apart, so it is hard to judge how much time to set aside. Find the smallest amount of time the friends need to meet in a single city.
The map holds cities and roads. A road here is not a single link between two cities. It is a continuous route that passes through several cities in order.
Each test case gives the number of cities N, the number of friends P, and the number of roads M. Cities are numbered 1 through N.
For each friend i (1≤i≤P) you get:
For each road j (1≤j≤M) you get:
Every friend leaves at the same moment. Find the smallest time in which all of them can be in one city. If no city can hold all of them, print -1 instead of a time.
A meeting happens only in a city, and a friend who arrives early can wait for the others. No two cities are joined directly by more than one path. Once a friend reaches a city, that friend can switch between the roads passing through it at no extra cost.
The first line has the number of test cases T. Each test case follows in this format.
The first line holds N, P, and M, separated by spaces. The next P lines hold Xi and Vi. The next M lines hold Dj, Lj, then Cj,1 through Cj,Lj.
For each test case print one line in the form Case #x: y, where x is the case number starting at 1 and y is the answer for that case. If the friends cannot all meet in one city, print -1 in place of y.