# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
9319 |
2014-09-28T05:35:01 Z |
Yoon |
Your life (kriii2_Y) |
C++ |
|
0 ms |
3580 KB |
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;
int N,M;
vector< pair<int,int> > adj[100010];
vector<int> dijkstra(int src)
{
vector<int> dist(N+1,1234567890);
vector<bool> visited(N+1,false);
dist[src]=0; visited[src]=false;
while(true){
int closest=1234567890,here;
for(int i=1;i<=N;i++){
if(dist[i]<closest && !visited[i]){
here=i;
closest=dist[i];
}
}
if(closest==1234567890)break;
visited[here]=true;
for(int i=0;i<adj[here].size();i++){
int there=adj[here][i].first;
if(visited[there])continue;
int nextDist=dist[here]+adj[here][i].second;
dist[there]=min(dist[there],nextDist);
}
}
return dist;
}
int main()
{
int i,a,b;
scanf("%d %d",&N,&M);
for(i=1;i<=M;i++){
scanf("%d %d",&a,&b);
adj[a].push_back(make_pair(b,1));
}
vector<int> shortest=dijkstra(1);
int ret=shortest[N];
if(ret==1234567899)printf("-1\n");
else printf("%d\n",ret);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
3580 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Halted |
0 ms |
0 KB |
- |