标签:倍增 print bit pre node bsp size using play
大体按照 数学 图论 dp 数据结构 这样的顺序
模板集 这个真的只有模板了………………
·spfa
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 #define maxn 100005 5 ll n,m,k,l,a,b,c,d[maxn],s,visit[maxn]; 6 struct edge{int from,to,val;}; 7 vector<int>g[maxn];vector<edge>edges; 8 void add_edge(int f,int t,int v){ 9 g[f].push_back(k);edges.push_back({f,t,v});k+=1; 10 }void spfa(int s){ 11 for(int i=1;i<=n;i++)d[i]=2147483647;queue<int>q;q.push(s); 12 visit[s]=1,d[s]=0; 13 while(!q.empty()){int u=q.front();q.pop();visit[u]=0; 14 for(int i=0;i<g[u].size();i++){edge &e=edges[g[u][i]]; 15 if(d[e.to]>d[u]+e.val){d[e.to]=d[u]+e.val; 16 if(!visit[e.to])q.push(e.to),visit[e.to]=1; 17 } 18 } 19 } 20 } 21 int main(){ 22 cin>>n>>m>>s;for(int i=1;i<=m;i++)cin>>a>>b>>c,add_edge(a,b,c);spfa(s); 23 for(int i=1;i<=n;i++)cout<<d[i]<<" "; 24 }
·dj
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 #define maxn 100005 5 6 ll n,m,k,l,a,b,c,d[maxn],s,visit[maxn]; 7 struct edge{int from,to,val;}; 8 vector<int>g[maxn];vector<edge>edges; 9 void add_edge(int f,int t,int v){ 10 g[f].push_back(k);edges.push_back({f,t,v});k+=1; 11 } 12 13 struct node{int u,d; 14 bool operator <(node b)const{ 15 return d>b.d; 16 } 17 }; 18 void dj(int s){ 19 for(int i=1;i<=n;i++)d[i]=2147483647;priority_queue<node>q;q.push({s,0}); 20 visit[s]=1,d[s]=0; 21 while(!q.empty()){int u=q.top().u;q.pop();visit[u]=0; 22 for(int i=0;i<g[u].size();i++){edge &e=edges[g[u][i]]; 23 if(d[e.to]>d[u]+e.val){d[e.to]=d[u]+e.val; 24 if(!visit[e.to])q.push({e.to,d[e.to]}),visit[e.to]=1; 25 } 26 } 27 } 28 } 29 30 int main(){ 31 cin>>n>>m>>s; 32 for(int i=1;i<=m;i++)scanf("%lld%lld%lld",&a,&b,&c),add_edge(a,b,c); 33 dj(s);for(int i=1;i<=n;i++)printf("%lld ",d[i]); 34 return 0; 35 }
·网络流
·费用流
·kruscall
·倍增lca
·树剖
·lct
·无向图tarjan只割顶 桥
·流图tarjan
·2-sat
·点分(这个考就没意思了………………)
·拓扑排序和基环树
·缩点
标签:倍增 print bit pre node bsp size using play
原文地址:https://www.cnblogs.com/iboom/p/9912389.html