← 返回 citadel 的题目列表Shortest path in graph with fuel constraints and refueling stations
类型:online_judge
citadel
Given an undirected graph representing a transportation network where each edge has a cost of 1, you have a car with a fuel tank of limited capacity starting from a source node to a target node. Some nodes in the graph are gas stations where you can fill up the tank. Moving along an edge consumes 1 unit of fuel. Compute the shortest distance from the source node to the target node, assuming the number of nodes can reach up to 1 million.
Input Format:
The first line contains three integers n, m, and c, representing the number of nodes, the number of edges, and the capacity of the fuel tank.
The next m lines each contain two integers u, v, indicating an edge between node u and node v.
The following line contains two integers s, t, representing the source node s and the target node t.
The last line contains integers representing the nodes that are gas stations.
Output Format:
Output an integer representing the shortest distance from s to t. If it is unreachable, output -1.
Example
Input
5 5 3
0 1
0 2
1 3
2 3
3 4
0 4
0 3