diamond_153 @ 2022-12-18 12:04:57
自己想了一个特别拉跨的算法,32pts,不能过题,如果我这个算法有名字求大佬告诉我:
#include<iostream>
#include<map>
#include<vector>
#include<list>
#include<utility>
#define int long long
using namespace std;
int n,m,s;
int dis[301100]={0};
vector<map<int,int>> nexts(301100);//邻接表
void bfs(int s){//算法主体
for(int i=1;i<=n;i++)
dis[i]=(1<<31)-1;//初始化
dis[s]=0;
list<pair<int,int>> l{{s,0}};//存储
while(!l.empty()){
auto front=l.front();
for(auto i:nexts[front.first]){
if(dis[i.first]==-1||front.second+i.second<dis[i.first])
l.push_back({i.first,front.second+i.second}),
dis[i.first]=front.second+i.second;
}
l.pop_front();
}
}
signed main(){
ios::sync_with_stdio(false);
cin>>n>>m>>s;
for(int i=0;i<m;i++){
int u,v,w;
cin>>u>>v>>w;
if(!nexts[u][v])nexts[u][v]=w;
else nexts[u][v]=min(nexts[u][v],w);
}
bfs(s);
for(int i=1;i<=n;i++)
cout<<dis[i]<<" ";
}
算法的思想大概是广搜,先把起点放进队列,再取出队首,将所有与此点相邻的点路径更新。
by qwasd @ 2022-12-18 12:06:07
spfa?
by kevinchw @ 2022-12-18 12:07:01
bijkspfa(大雾
by Eleveslaine @ 2022-12-18 12:26:50
floydijkspfa(逃
by Usada_Pekora @ 2022-12-18 12:27:45
spfa。
by Magus @ 2022-12-18 12:31:32
spfa他死了
by _XHY20180718_ @ 2022-12-18 12:40:09
spfa,但是改了存储方式?
by 初雪_matt @ 2022-12-18 12:44:34
spfa
by Pursuewind @ 2022-12-26 19:32:59
这里
by MornHus @ 2023-01-07 22:33:16
这不就是spfa,我spfa就是32分
by yzwfq2000 @ 2023-02-09 15:04:02