답안 #9167

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
9167 2014-09-28T04:17:11 Z altertain Your life (kriii2_Y) C++14
4 / 4
76 ms 7580 KB
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cctype>
#include <cstring>
#include <queue>
#include <cassert>

using namespace std;

typedef long long LL;
typedef vector<string> VS;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<PII> VPII;

#define MP make_pair
#define ST first
#define ND second
#define PB push_back
#define FOR(i,a,b) for( int i=(a); i<(b); ++i)
#define FORD(i,a,b) for( int i=(a); i>(b); --i)
#define REP(i,n) for(int i=0; i<(n); ++i)
#define ALL(X) (X).begin(),(X).end()
#define SZ(X) (int)(X).size()
#define FORE(it,X) for(__typeof((X).begin()) it=(X).begin(); it!=(X).end();++it)

int dy[100005];
VI dt[100005];
int n,m;

int main()
{
	cin>>n>>m;
	
	REP(i, m) {
		int a,b;
		scanf("%d%d",&a,&b);
		a--,b--;
		dt[a].PB(b);
	}

	dy[0]=1;
	REP(i, n) if (dy[i]) {
		REP(j, SZ(dt[i])) {
			int v= dt[i][j];
			if (dy[v]) dy[v] = min(dy[v], dy[i]+1);
			else dy[v] = dy[i]+1;
		}
	}

	if (dy[n-1] == 0) cout<<-1<<endl;
	else cout<<dy[n-1]-1<<endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4412 KB Output is correct
2 Correct 0 ms 4412 KB Output is correct
3 Correct 0 ms 4412 KB Output is correct
4 Correct 0 ms 4412 KB Output is correct
5 Correct 0 ms 4412 KB Output is correct
6 Correct 0 ms 4412 KB Output is correct
7 Correct 0 ms 4412 KB Output is correct
8 Correct 0 ms 4412 KB Output is correct
9 Correct 0 ms 4412 KB Output is correct
10 Correct 16 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4412 KB Output is correct
2 Correct 28 ms 7448 KB Output is correct
3 Correct 56 ms 7448 KB Output is correct
4 Correct 52 ms 7448 KB Output is correct
5 Correct 56 ms 7448 KB Output is correct
6 Correct 16 ms 7448 KB Output is correct
7 Correct 44 ms 7448 KB Output is correct
8 Correct 76 ms 7580 KB Output is correct
9 Correct 32 ms 7448 KB Output is correct
10 Correct 64 ms 7184 KB Output is correct