#include<bits/stdc++.h>
using namespace std;
int n,m,s;
int ms[10010];
struct point{
int index,value;
};
struct cmp{
bool operator()(point a,point b){
return a.value<b.value;
}
};
priority_queue<point,vector<point>,cmp> P;
vector<point> V[10010];
bool vis[10010];
int main(){
// memset(ms,127,sizeof(ms));
// cout<<ms[1];
//
// freopen("P3371_2.in","r",stdin);
// freopen("P3371_2.out","w",stdout);
for(int i=0;i<10010;i++){
ms[i]=2147483647;
}
scanf("%d%d%d",&n,&m,&s);
for(int i=0;i<m;i++){
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
V[u].push_back(point{v,w});
}
P.push(point{s,0});
ms[s]=0;
while(!P.empty()){
point temp=P.top();
//cout<<temp.index<<endl;
P.pop();
if(vis[temp.index]==true)continue;
vis[temp.index]=true;
for(int i=0;i<V[temp.index].size();i++){
point t2=V[temp.index][i];
if(ms[temp.index]+t2.value<ms[t2.index]){
ms[t2.index]=ms[temp.index]+t2.value;
P.push(point{t2.index,ms[t2.index]});
}
}
}
cout<<ms[1];
for(int i=1;i<=n;i++){
// printf("%d ",ms[i]);
}
return 0;
}
if(vis[temp.index]==true)continue; vis[temp.index]=true;注释后能拿70,不注释就只能20,有点想不通问题出在哪里