#include <iostream>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;
int n , m , ans[2000] , u , v , w;
struct node1
{
int v , w;
};
struct node2
{
int x , d;
bool operator < (const node2 b) const
{
return d < b.d;
}
}now;
priority_queue <node2> q;
vector <node1> grath[2000];
int main()
{
memset (ans , -1 , sizeof (ans));
scanf("%d%d" , &n , &m);
for (int i = 1 ; i <= m ; i++)
{
scanf("%d%d%d" , &u , &v , &w);
grath[u].push_back(node1{v,w});
}
q.push(node2{1,0});
while (!q.empty())
{
now = q.top();
q.pop();
if (ans[now.x] != -1) continue;
ans[now.x] = now.d;
for (auto i : grath[now.x])
q.push(node2{i.v , now.d + i.w});
}
printf("%d" , ans[n]);
return 0;
}
这是优先队列的
看起来没有任何问题,但是过不了,可是只要换成了一般的队列,就直接过了