wzq100205 @ 2024-04-20 10:23:37
写假了(bushi)
题解没看明白
代码:
#include<bits/stdc++.h>
using namespace std;
struct qu{
int k;
int dis;
bool operator <(const qu &x)const{
return x.dis<dis;
}
bool operator >(const qu &x)const{
return x.dis>dis;
}
};
priority_queue<qu> num;
const int MAXN=1e5+10;
const int MAXM=2e5+10;
struct node{
int v;
int w;
int nxt;
};
int head[MAXN];
node edge[MAXM];
int dist[MAXN];
bool vis[MAXN];
int top=1;
int main(){
int n,m,s,u,v,w;
cin>>n>>m>>s;
for(int i=0;i<m;i++){
scanf("%d%d%d",&u,&v,&w);
int k=head[u];
if(k==0){
edge[top].nxt=0;
edge[top].v=v;
edge[top].w=w;
head[u]=top;
top++;
}else{
edge[top].nxt=k;
edge[top].v=v;
edge[top].w=w;
head[u]=top;
top++;
}
}
memset(dist,0x3f3f3f3f,sizeof(dist));
dist[s]=0;
num.push((qu){s,0});
while(num.size()){
u=num.top().k;
num.pop();
if(vis[u]==1)continue;
vis[u]=1;
for(int i=head[u];i;i=edge[i].nxt){
if(dist[edge[i].v]>dist[u]+edge[i].w){
dist[edge[i].v]=dist[u]+edge[i].w;
if(vis[edge[i].v]==0){
num.push((qu){v,dist[v]});
}
}
}
}
for(int i=0;i<n;i++){
cout<<dist[i]<<" ";
}
return 0;
}
by HenghengMoi @ 2024-05-10 15:37:51
第58行
num.push((qu){v,dist[v]});
v没有提前定义
改成这样
num.push((qu){edge[i].v,dist[edge[i].v]});
by wzq100205 @ 2024-05-18 11:57:33
@HenghengMoi thx
by wzq100205 @ 2024-05-18 12:00:12
@HenghengMoi emmm还不对我自己再调,但关注了
by wzq100205 @ 2024-05-18 12:01:43
@HenghengMoi 过了谢谢
by wzq100205 @ 2024-05-24 13:51:35
已AC,此贴结