This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<stdio.h>
#include<queue>
using namespace std;
typedef pair<int,int> Pi;
#define X first
#define Y second
priority_queue <int> edge[100010];
priority_queue <Pi, vector<Pi>, greater<Pi> >pq;
int st[100010], en[600060], nxt[600060], len[600060];
void add(int s,int e,int l,int c){nxt[c]=st[s],st[s]=c,en[c]=e,len[c]=l;}
int dis[100010];
bool chk[100010];
int main()
{
int n, m;
scanf("%d%d",&n,&m);
int i;
for(i=1;i<=m;i++){
int x, y, z;
scanf("%d%d%d",&x,&y,&z);
add(y,x,z,i);
edge[x].push(z);
}
pq.push(Pi(0,n));
while(!pq.empty()){
Pi tmp = pq.top();
pq.pop();
if(chk[tmp.Y])continue;
chk[tmp.Y] = 1;
dis[tmp.Y] = tmp.X;
for(i=st[tmp.Y];i;i=nxt[i]){
if(chk[en[i]])continue;
pq.push(Pi(edge[en[i]].top() + tmp.X, en[i]));
edge[en[i]].pop();
}
}
printf("%d",dis[1]);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |