In the event of technical difficulties with Szkopuł, please contact us via email at email@example.com.
If you are familiar with IRC chat, the support team is also reachable on PIRC network (
#szkopul channel. If you are not, just use email.
Please do not ask us things like "how to solve task XYZ?".
Please remember that the support team has to sleep sometimes or go to work in real life.
A salesman Byteasar works hard travelling over Byteotia. In past times travelling salesmen could choose on their own towns they wanted to visit and order to do so, but those times are now gone forever. From the time the Central Controlling Office for Travelling Salesmen was established every salesman gets from the Office a list of towns to visit and the order of his tour. As it usually happens with central offices, the imposed order of visiting towns has not much in common with an optimal order. Before leaving for his tour Byteasar would like to know at least how much time it will take him to visit all the towns. It is your task to compute this.
The towns of Byteotia are numbered from to . The capital of Byteotia has the number , and this is the place Byteasar starts on his journey from. The towns are connected by a network of two-way roads. A trip between two towns directly connected by a road always takes 1 unit of time. From the capital one can reach any other Byteotian town. However, the road network had been designed very thriftily, so the roads never form cycles.
Write a program which:
In the first line of the standard input there is one integer equal to the number of towns in Byteotia, . In the following lines the network of roads is described. In each of these lines there are two integers and (; ), meaning that the towns and are connected by a road. In the line there is one integer equal to the number of towns Byteasar should visit, . In the following lines there are numbers of successive towns on Byteasar's route - one number per line.
In the first and only line of the standard output there should be one integer equal to the total time of Byteasar's trip.
For the input data:
5 1 2 1 5 3 5 4 5 4 1 3 2 5
the correct result is:
Task author: Tomasz Walen.