pair真心好写,就是可扩展性不强
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#define MK(x,y) make_pair(x,y)
#define pii pair<int,int>
#define inf 0x3f3f3f3f
#define se second
#define fi first
using namespace std;
struct aa
{
int y,z,pre;
}edge[1000009];
int n,m,tot,head[100009],dis[100009];
bool b[100009];
void addedge(int x,int y,int z)
{
edge[++tot].y=y;edge[tot].z=z;edge[tot].pre=head[x];head[x]=tot;
}
int main()
{
scanf("%d%d",&m,&n);
int x,y,z;
for (int i=1;i<=m;i++) scanf("%d%d%d",&x,&y,&z),addedge(x,y,z),addedge(y,x,z);
priority_queue<pii,vector<pii>,greater<pii> > heap;
memset(dis,inf,sizeof(dis));
dis[1]=0;
memset(b,false,sizeof(b));
heap.push(MK(dis[1],1));
pii t;
while (!heap.empty())
{
t=heap.top();
heap.pop();
if (b[t.se]) continue;
b[t.se]=true;
for (int i=head[t.se];i;i=edge[i].pre)
if (!b[edge[i].y]&&dis[edge[i].y]>dis[t.se]+edge[i].z)
{
dis[edge[i].y]=dis[t.se]+edge[i].z;
heap.push(MK(dis[edge[i].y],edge[i].y));
}
}
printf("%d",dis[n]);
return 0;
}