제출 #9220

#제출 시각아이디문제언어결과실행 시간메모리
9220effservYour life (kriii2_Y)C++98
0 / 4
1000 ms3652 KiB
/* 문제


*/


// 2014.

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
#include <cstring>
#include <string>
#include <map>

using namespace std;

#define maxS	100001

vector <int> x[maxS];

int N, M , ans = 2100000000;

bool visited[maxS];

int cmp1(int i, int j)
{
	return i > j;
}

void dfs(int n, int m)
{
	if (ans <= m)
		return;

	int sz = x[n].size();
	for (int i = 0; i < sz; i++)
	{
		if (x[n][i] == N)
		{
			if (ans > m + 1)
				ans = m + 1;

			return;
		}
		
		dfs(x[n][i], m + 1);
	}

	return;
}

int main()
{

	scanf("%d%d", &N, &M);

	for (int i = 0; i < M; i++)
	{
		int n, m;
		scanf("%d%d", &n, &m);
		x[n].push_back(m);
	}
	
	for (int i = 1; i <= N; i++)
		sort(x[i].begin(), x[i].end(),cmp1);

	dfs(1, 0);

	if (ans == 2100000000)
		printf("-1\n");
	else
		printf("%d\n", ans);

	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...