#include<vector>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstdio>
#include<string.h>
using namespace std;
const int INF=0x3f3f3f3f;
const int MAXN=1000010;
struct qnode
{
int v,c;
bool operator <(const qnode &r)const
{
return c>r.c;
}
qnode(int a=0,int b=0):v(a),c(b) {};
};
struct Edge
{
int v,cost;
Edge(int a=0,int b=0):v(a),cost(b) {};
};
vector<Edge>E[MAXN];
bool vis[MAXN];
int dist[MAXN];
void Dijkstra(int n,int start)
{
memset(vis,0,sizeof(vis));
for(int i=0; i<=n; i++)
dist[i]=INF;
priority_queue<qnode>que;
while(!que.empty())
{
que.pop();
}
dist[start]=0;
qnode aaa;
aaa.v=start;
aaa.c=0;
que.push(aaa);
qnode tmp;
while(!que.empty())
{
tmp=que.top();
que.pop();
int u=tmp.v;
if(vis[u])
continue;
vis[u]=1;
for(int i=0; i<E[u].size(); i++)
{
int v=E[u][i].v;
int cost=E[u][i].cost;
if(!vis[v]&&dist[v]>dist[u]+cost)
{
dist[v]=dist[u]+cost;
aaa.v=v;
aaa.c=dist[v];
que.push(aaa);
}
}
}
}
int mapp[2002][2002]= {0};
int main()
{
memset(mapp,-1,sizeof(mapp));
int t,n;
cin>>t>>n;
for(int i=0; i<t; i++)
{
int a,b,c;
cin>>a>>b>>c;
Edge aa;
aa.v=b;
aa.cost=c;
E[a].push_back(aa);
aa.v=a;
aa.cost=c;
E[b].push_back(aa);
}
Dijkstra(n,1);
cout<<dist[n]<<endl;
}
08-25