#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
10196 KB |
Output is correct |
2 |
Correct |
0 ms |
10196 KB |
Output is correct |
3 |
Correct |
16 ms |
11076 KB |
Output is correct |
4 |
Correct |
164 ms |
19016 KB |
Output is correct |
5 |
Correct |
172 ms |
19016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
10196 KB |
Output is correct |
2 |
Correct |
4 ms |
10196 KB |
Output is correct |
3 |
Correct |
12 ms |
11128 KB |
Output is correct |
4 |
Correct |
64 ms |
14612 KB |
Output is correct |
5 |
Correct |
92 ms |
16736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
10856 KB |
Output is correct |
2 |
Correct |
20 ms |
10856 KB |
Output is correct |
3 |
Correct |
248 ms |
16928 KB |
Output is correct |
4 |
Correct |
284 ms |
17388 KB |
Output is correct |
5 |
Correct |
292 ms |
17392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
260 ms |
16928 KB |
Output is correct |
2 |
Correct |
240 ms |
16928 KB |
Output is correct |
3 |
Correct |
224 ms |
17192 KB |
Output is correct |
4 |
Correct |
284 ms |
18576 KB |
Output is correct |
5 |
Correct |
268 ms |
18580 KB |
Output is correct |