Problem
###Statement:
In a far away Galaxy of Tilky Way, there was a planet Tarth where the sport of Tompetitive Toding was very popular. According to legends, there lived a setter who loved giving optimized Dijkstra and Floyd Warshall algorithms in TCDSAP exams.
Commander Tresdin, having obtained stones, must hurry out of the abyss to save Stonehall! The abyss can be represented as an unweighted graph containing nodes and edges. The abyss is chaotic, and hence can be disconnected as well. out of these nodes are special nodes which have a portal to escape from the abyss.
Commander Tresdin met Rubik, the Grand Mage, who offered to help teleport her to the nearest portal. But for that, he needs to know the distance to the nearest portal (that is, the minimum number of edges that have to be traversed)! Hence, given queries, each giving a node , i.e. the Node where Commander Tresdin and Rubik are, print the distance to reach the nearest special node. Print if its not possible to reach a special node from their starting point.
###Input:
- The first line contains Number of test cases in a file.
- The first line of each test case has integers, , and , denoting number of nodes, number of edges, and number of special nodes respectively.
- Next lines have integers each - - denoting that there is an (undirected) edge between and .
- Next line has space separated integers denoting the special nodes.
- Next line has a single integer - the number of queries.
- Next lines contain integer each - - the starting node for Commander Tresdin.
###Output:
For every query, if its not possible to reach any special node by travelling along the given edges starting from node . Else, print the distance to the nearest special node.
###Constraints
- Sum of over all is
- Sum of over all is
- Sum of over all is
- does not have self loops or multiple edges.
###Subtasks
- 20% points - .
- 80% points - Original Constraints
###Sample Input:
1
5 3 3
1 2
1 3
2 3
1 3 5
5
1
2
3
4
5
###Sample Output:
0
1
0
-1
0
###EXPLANATION:
- Nodes , and themselves are special nodes and hence the minimum distance to a special node is (i.e. as Commander Tresdin already starts at a special node, she needs not travel any further to reach one).
- From Node , we can travel an edge to reach Node or Node , both at distance of .
- Node is disconnected from all special nodes.. Starting from Node , we cannot reach any special node. Hence is printed.
0 Comments