Professional Documents
Culture Documents
Input
The first line contains two space-separated integers: n, the number of routers and m, the number of
connections.
Then m lines follow, ith line contains three integers, routers ai and bi , connected through the ith
connection and ci , the transmission time between the mentioned routers.
Then n lines follow, ith line contains ki , number of time instances when the ith routers are busy. Then ki
space separated integers tij follow in sorted order. tij means that at this timestamp the router is in the
busy state and your packet has to wait for this second (if it is at this router at this timestamp).
For this sub task all ki0 s will be 0. All routers will be free for transmission at any given time.
Constraints:
• 2 ≤ n ≤ 105
• 0 ≤ m ≤ 105
• 1 ≤ ci ≤ 104
• Sum of ki = 0
• 1 ≤ ai , bi ≤ n
• 1 ≤ tij ≤ 109
Output
Print a single number — the least amount of time your packet needs to get from router 1 to router n. If
the packet can’t get to router n in any amount of time, print number −1.
Example
standard input standard output
3 2 7
1 2 3
2 3 4
0
0
0
Page 1 of 2
Note
It is guaranteed that there would be at most one connection between any pair of routers.
In the above example, the packet can jump from router 1->2 and then from 2->3 to reach the destination
in a total of 7 seconds. (3+4)
HashMaps and HashSets are not allowed for this problem.
Page 2 of 2