1 #include<cstdio>
2 #include<cstring>
3 #include<algorithm>
4 #define mem(a,p) memset(a,p,sizeof(a))
5 const int N=205,inf=0x3f3f3f3f;
6 struct node{int h[N][N];}mp,res;
7 int n,t,s,e,id[N],cnt=0;
8 int min(int a,int b){return a>b?b:a;}
9 int read(){
10 int ans=0,f=1;char c=getchar();
11 while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1;c=getchar();}
12 while(c>=‘0‘&&c<=‘9‘){ans=ans*10+c-48;c=getchar();}
13 return ans*f;
14 }
15 node mul(node a,node b){
16 node tem;
17 for(int i=1;i<=cnt;i++)
18 for(int j=1;j<=cnt;j++)tem.h[i][j]=inf;
19 for(int k=1;k<=cnt;k++)
20 for(int i=1;i<=cnt;i++)
21 for(int j=1;j<=cnt;j++)
22 tem.h[i][j]=min(tem.h[i][j],a.h[i][k]+b.h[k][j]);
23 return tem;
24 }
25 node mul1(node a,node b){
26 node tem;
27 for(int i=1;i<=cnt;i++)
28 for(int j=1;j<=cnt;j++)tem.h[i][j]=inf;
29 for(int k=1;k<=cnt;k++)
30 for(int j=1;j<=cnt;j++)
31 tem.h[id[s]][j]=min(tem.h[id[s]][j],a.h[id[s]][k]+b.h[k][j]);
32 return tem;
33 }
34 int ksm(){
35 while(n){
36 if(n&1)res=mul1(res,mp);//不想卡常的话可以直接写成mul
37 mp=mul(mp,mp);
38 n>>=1;
39 }
40 return res.h[id[s]][id[e]];
41 }
42 int main(){
43 n=read();t=read();s=read();e=read();
44 for(int i=1,a,b,c;i<=t;i++){
45 c=read();a=read();b=read();
46 if(!id[a])id[a]=++cnt;
47 if(!id[b])id[b]=++cnt;
48 int x=id[a],y=id[b];
49 mp.h[x][y]=mp.h[y][x]=c;
50 }
51 for(int i=1;i<=cnt;i++)
52 for(int j=1;j<=cnt;j++){
53 if(!mp.h[i][j])mp.h[i][j]=inf;
54 res.h[i][j]=i==j?0:inf;
55 }
56 printf("%d\n",ksm());
57 return 0;
58 }