#include<cstdio>
#include<queue>
#include<vector>
#include<cstring>
using namespace std;
int n,m,k;
int dis[100001];
vector<int>a[100001],zhi[100001];
bool fin[100001];
struct pp
{
int dian;
}dian;
priority_queue <pp>q;
bool operator <(pp a,pp b)
{
return dis[a.dian]>dis[b.dian];
}
void shengcheng()
{
for(int i=1;i<=n;i++)
{
dis[i]=1000000009;
}
dis[k]=0;
fin[k]=1;
while(q.empty()==0)
{
int u=q.top().dian;q.pop();
fin[u]=0;
for(int i=0;i<a[u].size();i++)
{
int w=a[u][i];
if(dis[w]>dis[u]+zhi[u][i])
{
dis[w]=dis[u]+zhi[u][i];
if(fin[w]==0)
{
fin[w]=1;
dian.dian=w;
q.push(dian);
}
}
}
}
}
int x,y,z;
int main()
{
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=m;i++)
{
scanf("%d%d%d",&x,&y,&z);
a[x].push_back(y);
zhi[x].push_back(z);
}
dian.dian=k;
q.push(dian);
shengcheng();
for(int i=1;i<=n;i++)
{
if(i!=k)
printf("%d ",dis[i]);
else
printf("0 ");
}
return 0;
}
我不会迪杰斯特拉,于是想出了这个来偷懒