liwi are very close friends. The BEST of friends.
, , , andTheir respective locations are represented as an undirected graph with nodes and edges. Both and are located at node . wants to travel to where liwi is, which is node , and wants to travel to where is, which is node .
As
and are very close to each other, they would like to travel together for as long as possible. Therefore, has made a job for you.He wants you to find out two paths of minimum length starting in , ending in and , respectively, such that they share the maximum number of edges.
Constraints
- , , , could potentially be equal to each other
- , , and are connected.
For 20% of the points, , and .
Input Specification
The first line of input will contain 2 space separated integers, and .
The second line of input will contain 3 space separated integers, , , and .
The final lines of input will contain and , representing that node is connected to , and vice versa.
Output Specification
You are to output a single integer, the maximum number of edges that
and will travel together on, while getting to each other's destination with the minimum distance.Sample Input 1
8 10
1 5 3
1 4
1 7
1 8
4 6
7 5
8 2
2 5
2 3
6 2
5 3
Sample Output 1
2
Sample Explanation
They can follow the path , and then split, the remaining person heading to . Therefore, they will stay on 2 edges together.
Comments