Submission #9426

# Submission time Handle Problem Language Result Execution time Memory
9426 2014-09-28T06:20:12 Z ksmail12 Your life (kriii2_Y) C++
0 / 4
0 ms 1680 KB
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>

using namespace std;

int main() {
    vector<vector<int> > g;
    vector<bool> v;
    queue<int> q;
    int n, m;
    int count = 0;
    scanf("%d %d", &n, &m);
    g.resize(n+1);
    v.resize(n+1);
    // make graph
    for (int i=m;i!=0;i--) {
        int x,y;
        scanf("%d %d", &x, &y);
        g[x].push_back(y);
    }
//    cout << "queue init start\n";
    // find solution
    q.push(1);
    v[1] = true;
//    cout << "queue init\n";
    while(!q.empty()) {
        int curr = q.front();
//        cout << "curr "<< curr << endl;
        
        q.pop();
        for(vector<int>::iterator it = g[curr].begin(); it!=g[curr].end();it++) {
            if(*it == n) {
                printf("%d\n", count+1);
                return 0;
            }
            if(!v[*it] && *it != n) {
                v[*it] = true;
                q.push(*it);
            }
        }

        count++;
    }

    return 0;   
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 1680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -