답안 #9391

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
9391 2014-09-28T06:04:27 Z jwvg0425 Your life (kriii2_Y) C++
1 / 4
1000 ms 60216 KB
#include<stdio.h>
#include<vector>
#include<queue>

std::vector<int> route[100000];
int length[100000];

int main(void)
{
	std::queue<int> queue;
	int N, M, x, y, min = -1;

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

	for (int i = 0; i < M; i++)
	{
		scanf("%d %d", &x, &y);
		route[x - 1].push_back(y - 1);
	}
	queue.push(0);

	for (int l = 0; !queue.empty(); l++)
	{
		int size = queue.size();

		for (int i = 0; i < size; i++)
		{
			int n = queue.front();
			queue.pop();

			if (length[n] != 0 && length[n] < l)
			{
				continue;
			}

			length[n] = l;
			if (n == N - 1)
			{
				min = l;
				goto END;
			}

			for (int j = 0; j < route[n].size(); j++)
			{
				queue.push(route[n][j]);
			}
		}
	}
END:
	printf("%d", min);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3972 KB Output is correct
2 Correct 0 ms 3972 KB Output is correct
3 Correct 0 ms 3972 KB Output is correct
4 Correct 0 ms 3972 KB Output is correct
5 Correct 0 ms 3972 KB Output is correct
6 Correct 0 ms 3972 KB Output is correct
7 Correct 0 ms 3972 KB Output is correct
8 Correct 0 ms 3972 KB Output is correct
9 Correct 0 ms 3972 KB Output is correct
10 Correct 20 ms 4500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3972 KB Output is correct
2 Correct 44 ms 7008 KB Output is correct
3 Execution timed out 1000 ms 60216 KB Program timed out
4 Halted 0 ms 0 KB -