U657682 Hack SPFA

题目背景

和 https://www.luogu.com.cn/problem/P4779 一样的输入格式,不过是**无向图**,有 $10^5$ 个点, $5\times 10^5$ 条边,保证图是联通的。 **没有针对某一特定 SPFA 的优化构造。** UPD:已经被 SPFA 通过了。[here](https://www.luogu.com.cn/record/261462310)

题目描述

gen: ```cpp line-numbers #include using namespace std; const int N=1e5; const int M=5e5; typedef long long ll; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); struct edge{ int v,nxt; ll w; }es[N*2+1000]; int head[N+100],gcnt; int rand(int l,int r){ return uniform_int_distribution(l,r)(rnd); } inline void add_edge(int u,int v,ll w){ es[++gcnt]={v,head[u],w};head[u]=gcnt; } long long dis[N]; void dfs(int u,int fa){ for(int i=head[u];i;i=es[i].nxt){ int v=es[i].v; ll w=es[i].w; if(v==fa) continue; dis[v]=dis[u]+w; dfs(v,u); } } int main(){ printf("%d %d 1\n",N,M); for(int i=2;i

输入格式

略

输出格式

略

说明/提示

一份可以通过的 dijkstra(去年写的,有点丑): ```cpp line-numbers #include #define int long long using namespace std; const int N=1e5+10; const int inf=2147483647; int n,m,s,t; struct Edge{ int v;long long k; bool operatoro.k; } }; vector g[N]; long long dis[N]; bool vis[N]; priority_queue q; signed main(){ cin>>n>>m>>s; for(int i=1;i>x>>y>>k; g[x].push_back({y,k}); g[y].push_back({x,k}); } //dijkstra //初始化 memset(dis,0x3f,sizeof dis); dis[s]=0; q.push({s,0}); while(!q.empty()){ Edge t=q.top(); //t.v 到达的点 t.k 距离 q.pop(); //cout