Submission #9519

# Submission time Handle Problem Language Result Execution time Memory
9519 2014-09-28T07:00:05 Z eternalklaus Your life (kriii2_Y) C++
0 / 4
0 ms 1752 KB
/*
 * y.cpp
 *
 *  Created on: 2014. 9. 28.
 *      Author: minque
 */





#include <iostream>

using namespace std;

int d[100+1][100+1];
int ds[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] && ds[curr][i]){
			v=dream(i);
			if(v == -1) ds[curr][i] = 0;
			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;
		ds[x][y] = ds[y][x] = 1;
	}
	int v = dream(m);
	cout<<v<<endl;
	return 0;
}


/*

 4 4
 1 2
 2 3
 3 4
 2 4

6 5
1 2
1 3
2 3
2 4
4 5
2 5

3 5
1 2
3 4
4 5


 * */
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1752 KB Output is correct
2 Incorrect 0 ms 1752 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -