#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<algorithm> #include<queue> #include<vector> using namespace std; int n,m,s,t,cnt,head[100001]; int dis[100001],vis[100001]; struct uio{ int to,nxt,wei; }edge[10000001]; struct cmp{ bool operator () (int x,int y) {return dis[x]>dis[y];}; }; priority_queue<int,vector<int>,cmp> que; void add(int x,int y,int z) { edge[++cnt].nxt=head[x]; edge[cnt].to=y; edge[cnt].wei=z; head[x]=cnt; } void dijkstra() { memset(dis,0x3f,sizeof(dis)); dis[s]=0; que.push(s); while(!que.empty()) { int x=que.top(); que.pop(); if(!vis[x]) { vis[x]=1; for(int i=head[x];i;i=edge[i].nxt) { int y=edge[i].to; dis[y]=min(dis[y],dis[x]+edge[i].wei); que.push(y); } } } } int main() { scanf("%d%d%d%d",&n,&m,&s,&t); for(int i=1;i<=m;i++) { int u,v,w; scanf("%d%d%d",&u,&v,&w); add(u,v,w); } dijkstra(); return 0; }