이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
* 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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |