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<algorithm>
#include<queue>
using namespace std;
typedef pair<int,int> ppair;
priority_queue< ppair,vector<ppair>,greater<ppair> >q;
int x,y,n,m,pos[100010],ch[100010];
vector<int>con[100010];
vector<int>arr[100010];
struct data{
int x,y,c;
bool operator<(const data&r)const{
return c>r.c;
}
}a[300010];
int main()
{
int i,p,s;
scanf("%d %d",&n,&m);
for(i=1;i<=m;i++){
scanf("%d %d %d",&a[i].x,&a[i].y,&a[i].c);
}
sort(a+1,a+m+1);
for(i=1;i<=m;i++)
{
arr[a[i].x].push_back(a[i].c);
con[a[i].y].push_back(a[i].x);
}
q.push(make_pair(0,n));
while(1)
{
p=q.top().second; s=q.top().first;
q.pop(); if(ch[p]) continue;
ch[p]=1;
if(p==1) break;
for(i=0;i<con[p].size();i++){
q.push(make_pair(s+arr[con[p][i]][pos[con[p][i]]],con[p][i]));
pos[con[p][i]]++;
}
}
printf("%d",s);
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... |