#include<iostream>
#include<vector>
#include<queue>
using namespace std;
#define VAL first
#define U second.first
#define V second.second
#define IN(a, b, c) make_pair(a, make_pair(b, c))
int main(){
int N, M; cin >> N >> M;
vector<vector<int> >adj(N+1);
vector<bool> visit(N + 1, false);
for (int i = 0; i < M; i++) {
int u, v; cin >> u >> v;
adj[u].push_back(v);
}
priority_queue <pair<int, pair<int, int> > >pq;
pq.push(IN(0, 0, 1));
while (true){
int val = -pq.top().VAL;
int u = pq.top().U;
int v = pq.top().V;
pq.pop();
if (v == N) {
cout << val << endl;
break;
}
for (int i = 0; i < adj[v].size(); i++){
if (!visit[adj[v][i]]) {
visit[adj[v][i]] = true;
pq.push(IN(-(val + 1), v, adj[v][i]));
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
1672 KB |
SIGSEGV Segmentation fault |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Halted |
0 ms |
0 KB |
- |