The theory of "algorithm" graph

Source: Internet
Author: User

"Shortest circuit"

BOOLSPFA () {memset (Vis,0,sizeof(VIS)); memset (d,0x3f,sizeof(d)); intHead=0, tail=1; q[0]=s;vis[s]=1;d [s]=0;  while(head!=tail) {         intX=q[head++];if(head> the) head=0;  for(intI=first[x];i;i=e[i]. from)          if(d[x]+e[i].w<D[E[I].V]) {               inty=e[i].v; D[y]=d[x]+E[I].W; if(!Vis[y]) {                    if(D[y]<d[q[head]]) {head--;if(head<0) head= the; q[head]=y;} Else{q[tail++]=y;if(tail> the) tail=0;} Vis[y]=1; }} Vis[x]=0; }    returnd[t];}
SPFA+SLF Optimization

"Strongly connected components"

https://www.byvoid.com/blog/scc-tarjan/

Http://www.cnblogs.com/saltless/archive/2010/11/08/1871430.html

voidTarjan (intx) {Dfn[x]=low[x]=++Mark; s[++top]=x;lack[x]=top;  for(intI=first[x];i;i=e[i]. from)     {         inty=e[i].v; if(!Dfn[y])              {Tarjan (y); LOW[X]=min (low[x],low[y]); }         Else if(!col[y]) low[x]=min (low[x],dfn[y]); }    if(dfn[x]==Low[x]) {Color++;  for(inti=lack[x];i<=top;i++) col[s[i]]=color; Num[color]=top-lack[x]+1; Top=lack[x]-1; }} for(intI=1; i<=n;i++)if(!dfn[i]) Tarjan (i);
View Code

"Bzoj" 1051 [HAOI2006] Popular cows (templates)

"Bzoj" 2208 [Jsoi2010] connectivity number (classic)

"Edge Dual connected components"

The cut-top judgment of the graph:

#include <cstdio>#include<algorithm>using namespacestd;Const intmaxn=100000, maxm=100000;structedge{intU,v, from;} e[maxm*3];intfirst[maxn],mark,dfn[maxn],low[maxn],iscut[maxn],tot,n,m;voidInsertintUintv) {Tot++;e[tot].v=v;e[tot].u=u;e[tot]. from=first[u];first[u]=tot;}voidDfsintXintFA) {Dfn[x]=low[x]=++Mark; intChild=0;  for(intI=first[x];i;i=e[i]. from)     if(e[i].v!=a) {         inty=e[i].v; if(!Dfn[y]) { Child++;//ImportantDFS (Y,X); LOW[X]=min (low[x],low[y]); if(Low[y]>=dfn[x]) iscut[x]=1; }         Else /*if (dfn[y]<dfn[x])*/low[x]=min (low[x],dfn[y]); }    if(fa<0&&child<=1) iscut[x]=0;}intMain () {scanf ("%d%d",&n,&m);  for(intI=1; i<=m;i++)     {         intu,v; scanf ("%d%d",&u,&v);     Insert (u,v); insert (v,u); }     for(intI=1; i<=n;i++)if(!dfn[i]) DFS (i,-1);  for(intI=1; i<=n;i++)if(Iscut[i]) printf ("%d", i);p rintf ("\ n"); return 0;}
View Code

"POJ" 3177 redundant Paths

"Point two connected components"

There seems to be some unclear questions, usually with the use of the side of the dual-connected component-based.

"LA" 5135 Mining Your Own Business

The theory of "algorithm" graph

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.