xinxin2022 @ 2024-07-09 10:57:00
dalao们能否帮本蒟蒻看看复活SPFA的计划哪里出毛病了吗?
#include<bits/stdc++.h>
using namespace std;
const int INF=INT_MAX;
const int mm=10;
const int ll=48;
int n,m,s;
struct node{
int to,lon;
};
vector<node> p[100005];
int dis[100005];
bitset<100005> vis;
int u,v,w;
priority_queue<int> q;
inline void read(int& k){
k=0;
char c=getchar();
for(;c>'9'||c<'0';)
{
c=getchar();
}
for(;c<='9'&&c>='0';){
k=k*mm+int(c-ll);
c=getchar();
}
}
void spfa(){
dis[s]=0;
q.push(s);
vis&=0;
for(;!q.empty();){
int rp=q.top();
q.pop();
vis[rp]=true;
for(int i=0;i<p[rp].size();i++){
if(dis[p[rp][i].to]>dis[rp]+p[rp][i].lon+1){
dis[p[rp][i].to]=dis[rp]+p[rp][i].lon;
if(!vis[p[rp][i].to]){
q.push(p[rp][i].to);
vis[p[rp][i].to]=true;
}
}
}
//vis[rp]=false;
}
}
signed main(){
cin>>n>>m>>s;
for(int i=1;i<=m;i++){
read(u);read(v);read(w);
p[u].push_back((node){v,w});
}
for(int i=1;i<=n;i++) dis[i]=INF;
spfa();
for(int i=1;i<=n;i++){
printf("%d ",dis[i]);
}
return 0;
}
WA32分