Strong connected components of a forward connected graph without heavy edges

Source: Internet
Author: User

1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <vector>5#include <stack>6 using namespacestd;7 intN,m,ntime;//ntime Log DFS access time8 intinstack[11000];//whether the marker point is in the stack9 intdfn[11000];//The number of access to the node during the DFS process (also called the start time)Ten intlow[11000];//The start time of the first node in the DFS process from which the node below the node (the start time is greater than the start time of the node, and the node reachable by the node) can reach the beginning of the initial low array equal to the DFN array Onevector<vector<int> >G; Astack<int>St; - voidTarjan (intu) - { the     inti,v; -dfn[u]=low[u]=ntime++; - st.push (u); -instack[u]=1; +      for(i=0; I<g[u].size (); i++)//each side starting from U -     { +v=G[u][i]; A         if(dfn[v]==0)//v hasn't been visited yet. at         { - Tarjan (v); -low[u]=min (low[u],low[v]); -         } -         Else if(Instack[v])//v in the stack -         { inlow[u]=min (low[u],dfn[v]); -         } to     } +     if(Dfn[u]==low[u])//U is the root of a strongly connected component -     { the          Do *         { $v=st.top ();Panax Notoginseng St.pop (); -instack[v]=0; theprintf"%d", v);//outputs the number of all points that belong to this strongly connected component +} while(u!=v); Aprintf"\ n"); the     } + } - intMain () $ { $      inti; -       while(SCANF ("%d%d", &n,&m)! =EOF) -      { the g.clear (); -G.resize (11000);Wuyi       while(!st.empty ()) St.pop (); theNtime=1; -memset (Instack,0,sizeof(Instack)); Wumemset (DFN,0,sizeof(DFN)); -memset (Low,0,sizeof(Low)); About      intu,v; $       for(i=0; i<m;i++)//point numbering starting from 1 -      { -scanf"%d%d",&u,&v); - G[u].push_back (v); A      } +Tarjan (1); the      } -      return 0; $}

Strong connected components of a forward connected graph without heavy edges

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.