POJ 3180 the Cow Prom (strong unicom)

Source: Internet
Author: User

John's N (2≤n≤10000) cows are very excited because it's prom night!         They wear dresses and new shoes, not flowers, they want to perform a round dance. Only cows can perform this round dance. The round dance needs some ropes and a round pool. The cows were standing around the pool, numbered 1 to n in the clockwise order. Every cow is faced with a pool so she can see every other cow. In order to dance this round, they found the M (2≤m≤50000) rope. On the hoof of several cows, one end of the rope is held, the rope bypasses the pool clockwise, and the other end is tied to another cow. In this way, some cows can pull other cows. Some cows may hold a lot of ropes, and some cows may not have a rope. For example, Bessie, her round dance success, can be tested: Along her traction rope, find her traction cows, and then along the rope traction of the cow, and found a pulled cow, so down, if finally can return to the position, then her round dance jump success, Because the cows on this ring can pull counterclockwise and jump to the dance of the round.        If you can't get back in position, her round dance is not successful.        If two of the successful round-dancing cows are connected by ropes, they can belong to a combination. Give a description of each rope, and find out how many combinations of cows have successfully danced round the dance? Problem Analysis: The demand is that there are several strong unicom components greater than or equal to 2;
#include <iostream>#include<cstdio>#include<cmath>#include<cstring>#include<cstdlib>#include<algorithm>#include<vector>UsingNamespace std;#defineINF 0X7FFFFFF#defineMAXN 10005typedef longlong LL;#defineMin (A, B) (A&LT;B?A:B)#defineMOD 1000000007intm, N, Time, top, ans;intSTACK[MAXN], DFN[MAXN], LOW[MAXN];BOOLInstack[maxn];vector<vector<int> >G;voidinit () {memset (DFN,0,sizeof(DFN)); memset (Low,0,sizeof(low)); Ans= time = top =0;    G.clear (); G.resize (n+2);}voidTarjan (intu) {Dfn[u]= Low[u] = + +Time ; Stack[top++] =u; Instack[u]=true; intLen = G[u].size (), V, k =0;  for(intI=0; i<len; i++) {v=G[u][i]; if( !Low[v])            {Tarjan (v); Low[u]=min (Low[u], low[v]); } elseif (Instack[v]) Low[u]=min (Low[u], dfn[v]); }    if(Low[u] = =Dfn[u]) {         Do{v= stack[--top]; K++; Instack[u]=false; } while(U! =v); if(k >=2) ans++; }}voidsolve () { for(intI=1; i<=n; i++)    {        if(!Low[i])    Tarjan (i); } printf ("%d\n", ans);}intMain () { while(SCANF ("%d%d", &n, &m)! =EOF)        {init ();  while(M--)        {            intA, B; scanf ("%d%d", &a, &b);        G[a].push_back (b);    } solve (); } Return0;}

POJ 3180 the Cow Prom (strong unicom)

Related Article

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.