Submission #9541

# Submission time Handle Problem Language Result Execution time Memory
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';
}
# Verdict Execution time Memory 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
# Verdict Execution time Memory 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