This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
 * y.cpp
 *
 *  Created on: 2014. 9. 28.
 *      Author: minque
 */
#include <iostream>
using namespace std;
int d[100+1][100+1];
int dream(int curr){
	if(curr == 1) return 0;
	int n = -1;
	int v = 0;
	for(int i = 1; i <= curr; i++){
		if(d[curr][i]){
			v=dream(i);
			if(n == -1 || v < n) n = v;
		}
	}
	return (n < 0 ? n : n+1);
}
int main(){
	int n, m;
	cin>>n>>m;
	for(int i = 0; i < n; i++){
		int x, y;
		cin>>x>>y;
		d[x][y] = d[y][x] = 1;
	}
	int v = dream(m);
	cout<<v<<endl;
	return 0;
}
/*
 4 4
 1 2
 2 3
 3 4
 2 4
 * */
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |