이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<stdio.h>
#include<queue>
#include<vector>
using namespace std;
#define M 100005
struct me{
int x,y;
bool operator < (const me &A)const{
return y>A.y;
}
};
me t,qu;
priority_queue< me > heap;
vector<int> a[M];
int n,m,re[M];
void dijkstra(int x){
int i;
t.x=x; t.y=re[x]; heap.push(t);
while(1){
if(heap.empty()) break;
t=heap.top();
heap.pop();
for(i=0;i < a[t.x].size();i++){
if(re[a[t.x][i]]==0 || re[a[t.x][i]]>re[t.x]+1){
re[a[t.x][i]]=re[t.x]+1;
qu.x=a[t.x][i]; qu.y=re[a[t.x][i]];
heap.push(qu);
}
}
}
}
int main()
{
int i,x,y;
scanf("%d %d",&n,&m);
for(i=0;i<m;i++){
scanf("%d %d",&x,&y);
a[x].push_back(y);
}
dijkstra(1);
if(re[n]==0) printf("-1\n");
else printf("%d\n",re[n]);
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |