14991 - Degree of Separation   

Description

In the modern era, social networks tightly connect people from all over the world. There is a famous concept known as the "Six Degrees of Separation," which suggests that any two people on Earth are at most six social connections away from each other.

You are currently working as a data analyst for a booming social media startup, "ConnectU". ConnectU operates multiple social platforms, and your manager wants you to analyze the efficiency of information spread per platform.

Specifically, each of ConnectU's social platforms can be viewed as a social network in the form of an undirected graph. Each user is a (unique) vertex in the graph, while a (mutual) social connection between two users is an edge in the graph between the two vertices. To analyze the efficiency of information spread in a social network, you need to calculate the Degree of Separation---the minimum number of social connections required to link a specific "starting user" to a "target user".

Given a social network for a ConnectU social platform containing N users and M social connections, write a C/C++ program to find the degree of separation between user S and user T. Note: the distance between a user and themselves is 0.

Your program MAY use C/C++ standard library headers.

Input

The first line contains two integers N and M (1 <= N <= 100,000, 0 <= M <= 200,000), representing the total number of users and the number of social connections, respectively. Users are numbered from 0 to N-1.

The next M lines each contain two integers U and V, representing a social connection between user U and user V (0 <= U, V < N and U != V).

The last line contains two integers S and T, representing the identifiers of the starting user and the target user, respectively.

(Note: The input test cases may contain duplicate social connections, which should simply be treated as a single social connection when processing.)

Output

Output a single integer on a single line representing the degree of separation between user S and user T. If there is no possible path connecting the two users (meaning they belong to completely isolated social circles), output -1.

Each line of output must be terminated by a newline character ('\n').

Sample Input  Download

Sample Output  Download

Tags

yan_ds



Discuss