Submission #9820

# Submission time Handle Problem Language Result Execution time Memory
9820 2014-09-28T10:54:59 Z Yoon Your life (kriii2_Y) C++
4 / 4
92 ms 8092 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);
	dist[src]=0;
	priority_queue< pair<int,int> > pq;
	pq.push(make_pair(0,src));
	while(!pq.empty()){
		int cost=-pq.top().first;
		int here=pq.top().second;
		pq.pop();
		if(dist[here]<cost)continue;
		for(int i=0;i<adj[here].size();++i){
			int there=adj[here][i].first;
			int nextDist=cost+adj[here][i].second;
			if(dist[there]>nextDist){
				dist[there]=nextDist;
				pq.push(make_pair(-nextDist,there));
			}
		}
	}
	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==1234567890)printf("-1\n");
	else printf("%d\n",ret);
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3580 KB Output is correct
2 Correct 0 ms 3580 KB Output is correct
3 Correct 0 ms 3580 KB Output is correct
4 Correct 0 ms 3580 KB Output is correct
5 Correct 0 ms 3580 KB Output is correct
6 Correct 0 ms 3580 KB Output is correct
7 Correct 0 ms 3580 KB Output is correct
8 Correct 0 ms 3580 KB Output is correct
9 Correct 0 ms 3580 KB Output is correct
10 Correct 20 ms 4672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3972 KB Output is correct
2 Correct 52 ms 7008 KB Output is correct
3 Correct 60 ms 7140 KB Output is correct
4 Correct 52 ms 7008 KB Output is correct
5 Correct 56 ms 7140 KB Output is correct
6 Correct 32 ms 7008 KB Output is correct
7 Correct 40 ms 7008 KB Output is correct
8 Correct 92 ms 8092 KB Output is correct
9 Correct 52 ms 7008 KB Output is correct
10 Correct 68 ms 7404 KB Output is correct