답안 #9541

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
9541 2014-09-28T07:07:29 Z jaehadad Your life (kriii2_Y) C++14
4 / 4
92 ms 7704 KB
#include<cstdio>
#include<cassert>
#include<cstring>
#include<map>
#include<set>
#include<time.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<utility>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int n, m;
vector<int> adj[100000];
const int LARGE = 987654321;
int main() {
  cin.sync_with_stdio(false);

  cin >> n >> m;
  for(int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    adj[a].push_back(b);
  }

  vector<int> c(n);
  c[n-1] = 0;
  for(int i = n-2; i >= 0; --i) {
    c[i] = LARGE;
    for(int j: adj[i]) 
      c[i] = min(c[i], c[j] + 1);
  }

  cout << (c[0] == LARGE ? -1 : c[0]) << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4012 KB Output is correct
2 Correct 0 ms 4012 KB Output is correct
3 Correct 0 ms 4012 KB Output is correct
4 Correct 0 ms 4012 KB Output is correct
5 Correct 0 ms 4012 KB Output is correct
6 Correct 0 ms 4012 KB Output is correct
7 Correct 0 ms 4012 KB Output is correct
8 Correct 0 ms 4012 KB Output is correct
9 Correct 0 ms 4012 KB Output is correct
10 Correct 16 ms 4676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4404 KB Output is correct
2 Correct 44 ms 7572 KB Output is correct
3 Correct 72 ms 7572 KB Output is correct
4 Correct 56 ms 7572 KB Output is correct
5 Correct 60 ms 7572 KB Output is correct
6 Correct 44 ms 7572 KB Output is correct
7 Correct 44 ms 7572 KB Output is correct
8 Correct 92 ms 7704 KB Output is correct
9 Correct 52 ms 7572 KB Output is correct
10 Correct 80 ms 7308 KB Output is correct