JIANG_YANG @ 2022-08-19 11:21:17
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
struct My_parter_is_sb {
int u,v,w;
} e[10086111];
int n,m,s;
long long dis[100816];
int main() {
cin>>n>>m>>s;
for(int i=1; i<=m; ++i) {
cin>>e[i].u>>e[i].v>>e[i].w;
}
for(int i=1; i<=n; ++i) {
dis[i]=0x7fffffff;
}
dis[s]=0;
int f=1;
while(f) {
f=0;
for(int i=1; i<=m; ++i) {
int u=e[i].u;
int v=e[i].v;
int w=e[i].w;
if(dis[v]>dis[u]+w) {
dis[v]=dis[u]+w;
f=1;
}
}
}
for(int i=1; i<=n; ++i) {
cout<<dis[i]<<" ";
}
return 0;
}
by xzy090626 @ 2022-08-19 11:27:34
@JIANG_YANG 您这纯纯 Bellman-Ford 能过就怪了。
by LYqwq @ 2022-08-19 11:28:09
@JIANG_YANG BF去交弱化版吧,标准版能过就是奇迹了
by huang_hun @ 2022-08-19 11:28:14
@xzy090626 感觉这BF都不是
by xzy090626 @ 2022-08-19 11:29:07
@LYqwq 弱化版也过不了(
by LYqwq @ 2022-08-19 11:29:10
@huang_hun 写法很扭曲,但本质应该是BF
by LYqwq @ 2022-08-19 11:29:35
@xzy090626 草()
by huang_hun @ 2022-08-19 11:30:18
@huang_hun 哦看错了,是BF
by xzy090626 @ 2022-08-19 11:30:34
建议lz学习使用优先队列/线段树/斐波那契堆优化的 Dijkstra 算法。
by whhsteven @ 2022-08-19 11:34:00
本题 BF 过不了。
by MvemiY @ 2022-08-19 11:59:20
@xzy090626 所以普通堆优dijk就能过