"Strong Unicom Component Indent" "Search" bzoj2208 [Jsoi2010] Connectivity number

Source: Internet
Author: User

Two times Dfs shrinks, and then n times DFS bursts.

1#include <cstdio>2#include <vector>3#include <cstring>4 using namespacestd;5 #defineN 20016vector<int>G[n],rg[n],vs,g2[n];7typedef vector<int>:: iterator ITER;8 Chars[n+1][n+1];9 intCmp[n],sum,cnt[n],ans,n;Ten BOOLVis[n]; One voidDfsintU) A { -vis[u]=1; -      for(ITER it=g[u].begin (); It!=g[u].end (); it++) the       if(!vis[*it]) -DFS (*it); - Vs.push_back (U); - } + voidDFS2 (intU) - { +vis[u]=1; Acmp[u]=sum; atcnt[sum]++; -      for(ITER it=rg[u].begin (); It!=rg[u].end (); it++) -       if(!vis[*it]) -DFS2 (*it); - } - voidSCC () in { -      for(intI=1; i<=n;i++) to       if(!Vis[i]) + DFS (i); -memset (Vis,0,sizeof(Vis)); theITER It=vs.end (); it--; *      for(;; it--) $       {Panax Notoginseng         if(!vis[*it]) -           { thesum++; +DFS2 (*it); A           } the         if(It==vs.begin ()) Break; +       } -memset (Vis,0,sizeof(Vis)); $ } $ voidDFS3 (intU) - { -vis[u]=1; ans+=Cnt[u]; the      for(ITER it=g2[u].begin (); It!=g2[u].end (); it++) -       if(!vis[*it])WuyiDFS3 (*it); the } - intMain () Wu { -scanf"%d",&n); About      for(intI=1; i<=n;i++) $       { -scanf"%s", s[i]+1); -          for(intj=1; j<=n;j++) -           if(s[i][j]=='1') A             { + G[i].push_back (j); the G[j].push_back (i); -             } $       } the SCC (); the      for(intI=1; i<=n;i++) the        for(intj=1; j<=n;j++) the         if(s[i][j]=='1'&&cmp[i]!=Cmp[j]) - G2[cmp[i]].push_back (Cmp[j]); in      for(intI=1; i<=sum;i++) the       { thememset (Vis,0,sizeof(Vis)); About DFS3 (i); the       } theprintf"%d\n", ans); the     return 0; +}

"Strong Unicom Component Indent" "Search" bzoj2208 [Jsoi2010] Connectivity number

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.