喀拉客 @ 2022-08-21 17:14:21
照着书上查了好几遍了,还是没有找出bug在何方
求大佬帮我看看
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
bool operator<(const pii &a,const pii &b)
{
return a.first>b.first;
}
priority_queue<pii> q;
const int maxn=200000+5;
int n,m,s,tot;
int head[maxn],ver[maxn],edge[maxn],Next[maxn];
long long d[maxn];
bool v[maxn];
void add(int x,int y,int z)
{
ver[++tot]=y,edge[tot]=z;
Next[tot]=head[x],head[x]=tot;
}
int main()
{
scanf("%d%d%d",&n,&m,&s);
for(int i=1;i<=m;++i)
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
add(u,v,w);
}
//memset(d,0x3f,sizeof(d));
for(int i=1;i<=n;++i)d[i]=1e10;
memset(v,0,sizeof(v));
d[s]=0;
q.push(make_pair(0,s));
while(q.size())
{
int x=q.top().second;
q.pop();
if(v[x])continue;
v[x]=1;
for(int i=head[x];i;i=Next[i])
{
int y=ver[i],z=edge[i];
if(d[y]>(long long)d[x]+z)
{
d[y]=d[x]+z;
q.push(make_pair(d[y],y));
}
}
}
for(int i=1;i<=n;++i)printf("%lld ",d[i]);
return 0;
}
by sun_fish @ 2022-08-21 17:39:57
知道哪了吗