HDU 3639 SCC Hawk-and-chicken

Source: Internet
Author: User

The SCC is shrunk to count the number of points in each SCC.

Then statistics can reach u the number of points, you can reverse the mapping, and then DFS again statistics.

Finally, it is necessary to open a tag array, because there are heavy edges in the test data, and the result is infinite WA.

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5#include <vector>6#include <stack>7 using namespacestd;8 9 Const intMAXN = the+Ten;Ten intN, M; Onevector<int>G[MAXN]; A  -stack<int>S; - intPRE[MAXN], LOWLINK[MAXN], SCCNO[MAXN], SZ[MAXN], Dfs_clock, scc_cnt; the  - voidDfsintu) - { -Pre[u] = Lowlink[u] = + +Dfs_clock; + s.push (u); -  +      for(inti =0; I < g[u].size (); i++) A     { at         intv =G[u][i]; -         if(!Pre[v]) -         { - Dfs (v); -Lowlink[u] =min (Lowlink[u], lowlink[v]); -         } in         Else if(!sccno[v]) lowlink[u] =min (Lowlink[u], pre[v]); -     } to  +     if(Pre[u] = =Lowlink[u]) -     { thescc_cnt++; *          for(;;) $         {Panax Notoginseng             intx =S.top (); S.pop (); -SCCNO[X] =scc_cnt; thesz[scc_cnt]++; +             if(x = = u) Break; A         } the     } + } -  $ voidFIND_SCC () $ { -Dfs_clock = scc_cnt =0; -memset (PRE,0,sizeof(pre)); thememset (Sccno,0,sizeof(SCCNO)); -memset (SZ,0,sizeof(SZ));Wuyi      for(inti =0; I < n; i++)if(!Pre[i]) DFS (i); the } -  Wu intSUPPORT[MAXN]; - intINDEG[MAXN]; About BOOLVIS[MAXN]; $vector<int>G2[MAXN]; -  - intDFS2 (intu) - { A     intAns =Sz[u]; +Vis[u] =true; the      for(inti =0; I < g2[u].size (); i++) -     { $         intv =G2[u][i]; the         if(Vis[v])Continue; theAns + =DFS2 (v); the     } the     returnans; - } in  the intMain () the { About     intT scanf"%d", &T); the      for(intKase =1; Kase <= T; kase++) the     { thescanf"%d%d", &n, &m); +          for(inti =0; I < n; i++) g[i].clear (); -          while(m--) the         {Bayi             intU, v; scanf"%d%d", &u, &v); the G[u].push_back (v); the         } -  - FIND_SCC (); the  thememset (Indeg,0,sizeof(indeg)); the          for(inti =1; I <= scc_cnt; i++) g2[i].clear (); the          for(inti =0; I < n; i++) -              for(intj =0; J < G[i].size (); J + +) the             { the                 intU = sccno[i], V =Sccno[g[i][j]]; the                 if(U = = v)Continue;94indeg[u]++; the g2[v].push_back (u); the             } the 98         intAns =0; About          for(inti =1; I <= scc_cnt; i++)if(!Indeg[i]) -         {101memset (Vis,false,sizeof(Vis));102Support[i] =DFS2 (i);103Ans =Max (ans, support[i]);104         } the 106printf"Case %d:%d\n", Kase, ans-1);107         BOOLFlag =false;108          for(inti =0; I < n; i++)109         { the             intU =Sccno[i];111             if(!indeg[u] && support[u] = =ans) the             {113                 if(flag) printf (" "); theprintf"%d", i); theFlag =true; the             }117         }118Puts"");119     } - 121     return 0;122}
code June

HDU 3639 SCC Hawk-and-chicken

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.