spfa 模板
来源:互联网 发布:用别人身份证开淘宝店 编辑:程序博客网 时间:2024/06/07 02:00
只是一个没有main的模板
#include <bits/stdc++.h>#define constant const constexprtypedef long long ll;typedef long double db;typedef std::string str;constant int maxN = 1e5 + 3;int N=5e6,M,P,Q,T;constant int iinf = 2147483647;constant ll linf = 9223372036854775807LL;constant ll mod = 1e9 + 7;constant db pi = std::acos(-1.0);constant db eps = 1e-8;typedef int intvec[maxN];typedef bool boolvec[maxN];typedef ll llvec[maxN];typedef db dbvec[maxN];typedef str strvec[maxN];typedef char c_str[maxN];template <typename T> inline constant T abs(T x) {return x>=0?x:-x;}inline db log2(db x) {return std::log(x)/std::log(2);}void quicker() {std::ios_base::sync_with_stdio(false);std::cin.tie(nullptr);}template <typename T> inline int sgn(T x){return x>eps?1:(x<-eps?-1:0);}intvec head,to,next;llvec weight;int edge_count;void init(){std::fill_n(head,maxN,-1);std::fill_n(to,maxN,-1);std::fill_n(next,maxN,-1);std::fill_n(weight,maxN,0LL);edge_count = 0;}void add(int u,int v,ll w){to[edge_count] = v;next[edge_count] = head[u];weight[edge_count] = w;head[u] = edge_count++;}void biadd(int u,int v,ll w){add(u,v,w);add(v,u,w);}llvec dist;intvec parent;boolvec in;std::stack<int> q;void spfa_init(){std::fill_n(dist,maxN,linf);std::fill_n(parent,maxN,-1);std::fill_n(in,maxN,false);while (!q.empty()) q.pop();}ll spfa(int u,int v){dist[u] = 0LL;q.emplace(u);in[u] = true;while (!q.empty()){int t = q.top();q.pop();in[t] = false;for (int i=head[t];i>=0;i=next[i]){int s = to[i];if (dist[s] > dist[t] + weight[i]){dist[s] = dist[t] + weight[i];parent[s] = t;if (!(in[s])){q.emplace(s);in[s] = true;}}}}return dist[v];}
阅读全文
0 0
- spfa模板
- spfa 模板
- SPFA模板
- SPFA 模板
- Spfa模板
- spfa---模板
- SPFA(模板)
- spfa模板
- SPFA模板
- SPFA 模板
- SPFA模板
- SPFA模板
- SPFA模板
- SPFA模板
- SPFA模板
- spfa 模板
- spfa 模板
- SPFA 模板
- 数据库SQL中的数据类型转换
- 文章标题
- mybatis逆向工程+PageHelper分页插件+mysql大文本类型字段的查询
- EasyUI 之 DataGrid的两种赋值方法
- Http协议基础
- spfa 模板
- Web项目性能优化之减少HTTP请求次数优化
- java---用户注册
- shell 中的>/dev/null 2>&1 是什么鬼?
- 【opencv学习之十四】Opencv灰度直方图和均值化直方图
- Qt之操作Excel
- 读《精通正则表达式》之思维导图笔记——第一弹
- kamon文档翻译(一)
- 【转】Kubernetes高可用负载均衡与集群外服务访问实践