Tarjan, Cutting edge, bridge, cutting point

Source: Internet
Author: User

Here is the basic knowledge of Tarjan,

Cutting points and cutting edges

First to seek the cutting edge,

#include <cstdio>#include<iostream>#include<bits/stdc++.h>using namespaceStd;typedefLong Longll;typedef unsignedLong Longull;#defineLS (t<<1)#defineRS ((t<<1) |#defineMid ((l+r) >>1)#defineMk Make_pair#definePB Push_back#defineFi first#defineSe Second#defineMAXN 100001structEdge {intV,NXT;} E[MAXN*2];intHEAD[MAXN];BOOLqiao[maxn*2];intDFN[MAXN],LOW[MAXN];intN,m,cnt,num;voidAddintXinty) {e[++cnt].v=y,e[cnt].nxt=head[x],head[x]=CNT;}voidTarjan (intXintFA) {Dfn[x]=low[x]=++num;  for(intI=HEAD[X]; I I=e[i].nxt) {        inty=e[i].v; if(!Dfn[y])            {Tarjan (y,i); LOW[X]=min (low[x],low[y]); if(low[y]>Dfn[x]) {Qiao[i]=qiao[i^1]=1; }        } Else if(I!= (fa^1) ) {low[x]=min (low[x],dfn[y]); }    }}intMain () {CIN>>n>>m; CNT=1;  for(intI=1, X, y; i<=m; i++) {cin>>x>>y;    Add (x, y), add (y,x); }     for(intI=1; i<=n; i++) {        if(!Dfn[i]) {Tarjan (i,0); }    }     for(intI=2; i<cnt; i+=2) {        if(Qiao[i]) {cout<<e[i^1].v<<" "<<e[i].v<<Endl; }    }    return 0;}/*6-6*/

Here's the cut.

1#include <cstdio>2#include <iostream>3#include <bits/stdc++.h>4 using namespacestd;5typedefLong Longll;6typedef unsignedLong Longull;7 8 #defineLS (t<<1)9 #defineRS ((t<<1) |Ten #defineMid ((l+r) >>1) One  A #defineMk Make_pair - #definePB Push_back - #defineFi first the #defineSe Second -  - #defineMAXN 100001 - structEdge { +     intv,nxt; -} e[maxn*2]; + intHEAD[MAXN]; A BOOLCUT[MAXN]; at intDFN[MAXN],LOW[MAXN]; - intN,m,cnt,num,root; - voidAddintXinty) { -e[++cnt].v=y,e[cnt].nxt=head[x],head[x]=CNT; - } - voidTarjan (intx) { indfn[x]=low[x]=++num; -     intflag=0; to      for(intI=HEAD[X]; I I=e[i].nxt) { +         inty=e[i].v; -         if(!Dfn[y]) { the Tarjan (y); *low[x]=min (low[x],low[y]); $             if(low[y]>=Dfn[x]) {Panax Notoginsengflag++; -                 if(x!=root| | Flag>1) { thecut[x]=1; +                 } A             } the         }  +         Elselow[x]=min (low[x],dfn[y]); -     } $ } $  - intMain () { -Cin>>n>>m; theCnt=1; -      for(intI=1, X, y; i<=m; i++) {WuyiCin>>x>>y; the         if(x==y)Continue; - Add (x, y), add (y,x); Wu     } -      for(intI=1; i<=n; i++) { About         if(!Dfn[i]) { $root=i; - Tarjan (i); -         } -     } A      for(intI=1; i<=n; i++) { +         if(Cut[i]) { thecout<<i<<" "; -         } $     } thecout<<"it's a cut."<<Endl; the     return 0; the } the  - /* in 6 6 the 1 2 the 1 3 About 2 3 the 2 4 the 2 5 the 4 5 + */

Tarjan, Cutting edge, bridge, cutting point

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.