样例能过,#1只错d[1]
#include<bits/stdc++.h>
using namespace std;
struct edge
{
int v,w,next;
}e[1000001];
int en,first[10001],n,m,s,t,d[10001];
void addedge(int u,int v,int w)
{
en++;
e[en].v=v;
e[en].w=w;
e[en].next=first[u];
first[u]=en;
}
struct heap
{
int u,d;
bool operator<(const heap&rhs) const
{
return this->d>rhs.d;
}
};
void dijksta()
{
priority_queue<heap> q;
for(int c=1;c<=n;c++)
{
d[c]=2147483647;
}
d[s]=0;
q.push((heap)
{
s,d[s]
});
while(!q.empty())
{
heap x=q.top();
q.pop();
int u=x.u;
if(x.d!=d[u]) continue;
for(int c=first[u];c>=0;c=e[c].next)
{
int v=e[c].v,w=e[c].w;
if(d[u]+w<d[v])
{
d[v]=d[u]+w;
q.push((heap)
{
v,d[v]
});
}
}
}
}
int main()
{
ios::sync_with_stdio(0);
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
memset(first,-1,sizeof(first));
cin>>n>>m>>s;
int u,v,w;
for(int c=1;c<=m;c++)
{
cin>>u>>v>>w;
addedge(u,v,w);
addedge(v,u,w);
}
dijksta();
for(int c=1;c<=n;c++)
{
cout<<d[c]<<' ';
}
return 0;
}