AdvancedRating 1500
Time for News to Reach Everyone
In an unweighted undirected network, news starts at node s and crosses one edge per minute. Print the minutes until every node has heard it, or -1 if some node never hears it.
Input
n, m and s; then m lines 'u v'.
Output
One integer.
Sample 1
Input
4 3 1 1 2 2 3 3 4
Output
3
Sample 2
Input
3 1 1 1 2
Output
-1
Output appears here