Description
The N (2 <= n <=) cows is so excited:it ' s prom night! They is dressed in their finest gowns, complete with corsages and new shoes. They know that tonight they would each try to perform the Round Dance. Only cows can perform the Round Dance which requires a set of ropes and a circular the stock tank. To begin, the cows line up around a circular the stock tank and number themselves on clockwise order consecutively from 1..N. Each cow faces the tank so she can see the other dancers. They then acquire a total of M (2 <= M <= 50,000) ropes all of which is distributed to the cows who hold them in th Eir hooves. Each cow hopes to is given one or more ropes to hold in both she left and right hooves; Some cows might be disappointed. For the Round Dance-succeed for any given cow (say, Bessie), the ropes that she holds must is configured just right. To know if Bessie ' s dance are successful, one must examine the set of cows holding the other ends of hers ropes (if she has Any), along With the cows holding the other ends for any ropes they hold, etc. When Bessie dances clockwise around the tank, she must instantly pulled all the other cows in her group around clockwise, to O. Likewise, if she dances the other, she must instantly pulled the entire group counterclockwise (anti-clockwise in Bri Tish 中文版). Of course, if the ropes is not properly distributed then a set of cows might not form a proper dance group and thus can n OT succeed at the Round Dance. The one-to-one-happens is while only one rope connects and cows. One cow could pulling the other in one direction, but could not pulling the other direction (since pushing ropes is well-known t o be fruitless). Note that the cows must Dance in lock-step:a dangling cow (perhaps with just one rope) that's eventually pulled along di Squalifies a group from properly performing the Round Dance since she's not immediately pulled to lockstep with the Res T. Given the ropes and their distribution to cows, how many groups of cows CAn properly perform the Round Dance? Note that a set of ropes and cows might wrap many times around the stock tank.
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 a cow, such as Bessie, her round dance success, can be tested: along the ropes she pulled, find her traction cows, and then along the rope traction of the cow, and found a tractor-driven cows, so down, If she could eventually return to Bessie, her round dance would have been successful, as the cows on the ring could be pulled counterclockwise to jump to the whirling dance. If such a test cannot be completed, then her round dance is unsuccessful. 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? Input
* Line 1:two space-separated integers:n and M
* Lines 2..m+1:each line contains, space-separated integers a and B that describe a rope from cow A to cow B in the CL Ockwise direction.
Line 1th inputs N and M, followed by m lines of two integers a and B, indicating a traction b.output
* Line 1: A single line with A single integer This is the number of groups successfully dancing the Round Dance.
Number of cow combinations that successfully danced round.
Sample INPUT5 4
2 4
3 5
1 2
4 1
INPUT DETAILS:
ASCII Art for Round Dancing is challenging. Nevertheless, here is a
Representation of the cows around the stock tank:
_1___
/**** \
5/****** 2
//**tank**|
\ \********/
\ \******/3
\ 4____//
\_______/
Sample OUTPUT1
HINT
1,2,4 These three cows belong to a successful dance-dancing combination. and 3, 52 cows did not jump the successful round dance
I have not read the question ... All kinds of spit groove 233, and then turned over the problem, want to see if there is no topic, the results of an open is "bare tarjin", "strong connectivity components", such as concise and crisp, alas, so, I also write to read it (actually did not write before). Oh, incredibly a, or 1a,2b young people happy more ...
#include <cstdio>#include<algorithm>using namespacestd;structna{intX,y,ne; Na () {ne=0; }};intn,m,l[10001],r[10001],x,y,num=0, ans=0, top=0, df[10001],lo[10001],dfn=0, st[10001];na b[50001];BOOLpr[10001],inst[10001];void inch(intXinty) {num++; if(l[x]==0) L[x]=num;ElseB[r[x]].ne=num; b[num].x=x;b[num].y=y;r[x]=num;}voidTarjin (intx) {Pr[x]=1; DF[X]=lo[x]=++DFN; st[++top]=x;inst[x]=1; for(intI=l[x];i;i=b[i].ne) { if(!Pr[b[i].y]) {Tarjin (B[I].Y); LO[X]=min (lo[x],lo[b[i].y]); }Else if(Inst[b[i].y]) lo[x]=min (lo[x],lo[b[i].y]); } if(df[x]==Lo[x]) { intj,q=0; Do{J=st[top--]; INST[J]=0; Q++; } while(j!=x); if(q>1) ans++; }}intMain () {scanf ("%d%d",&n,&m); for(intI=1; i<=m;i++) {scanf ("%d%d",&x,&y); inch(x, y); } for(intI=1; i<=n;i++) if(!Pr[i]) Tarjin (i); printf ("%d\n", ans);}
bzoj:1654: [Usaco2006 jan]the Cow prom Cow ball