```cpp
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 500005
inline int read(){
int s=0,f=1;
char ch;
while(!isdigit(ch)){
if(ch=='-')f=-1;
ch=getchar();
}
while(isdigit(ch)){
s=s*10+ch-'0';
ch=getchar();
}
return s*f;
}
priority_queue<int,vector<int>,greater<int> >q;
struct gj{
int next;
int to;
int w;
}heap[MAX_N];
int head[MAX_N],cnt,n,m,s,d[MAX_N];
int link(int x,int y,int w){
heap[++cnt].next=head[x];
heap[cnt].w=w;
head[x]=cnt;
heap[cnt].to=y;
}
void solve(){
memset(d,1000000000,sizeof(d));
d[s]=0;
q.push(s);
while(q.size()){
int x=q.top();
q.pop();
for(int i=head[x];i;i=heap[i].next){
int y=heap[i].to,tot=heap[i].w;
if(d[y]>d[x]+tot){
d[y]=d[x]+tot;
q.push(y);
}
}
}
for(int i=1;i<=n;i++){
printf("%d ",d[i]);
}
}
int main(){
n=read(),m=read(),s=read();
while(m--){
int a,b,c;
a=read(),b=read(),c=read();
link(a,b,c);
}
solve();
return 0;
}
```
by 长沙市yz某同学 @ 2018-09-14 21:47:55
Orz
by 起名真的很难 @ 2018-09-14 21:53:03
@[长沙市yz某同学](/space/show?uid=114243) 您没有使用```vis```数组,肯定会T啊。。。
by Sai0511 @ 2018-09-14 21:54:33
@[长沙市yz某同学](/space/show?uid=114243) 而且```memset```不是这么用的。。
by Sai0511 @ 2018-09-14 21:55:04
memset最好只初值0………………
by 7KByte @ 2018-09-14 21:56:45
@[长沙市yz某同学](/space/show?uid=114243)
by 7KByte @ 2018-09-14 21:56:55
@[长沙市yz某同学](/space/show?uid=114243) 您可能是并没有完全理解```dijkstra```的原理,建议把原理弄明白了再来做题。
by Sai0511 @ 2018-09-14 22:00:37
谢谢,我是那个link函数的int的问题,要改成void,不是数组原因,已经A了
by 长沙市yz某同学 @ 2018-09-14 22:01:34
@[Sai_0511](/space/show?uid=114320) 。。。。
by 长沙市yz某同学 @ 2018-09-14 22:01:51
@[Sai_0511](/space/show?uid=114320) 我的D就是vist
by 长沙市yz某同学 @ 2018-09-14 22:02:27