Topological sort +DP
Puzzle: http://blog.csdn.net/PoPoQQQ/article/details/45194103
Http://www.cnblogs.com/mmlz/p/4448742.html
Through conversion ... The product of the $degree_i$ outside the path is transformed into the sum of the degree of all points divided by the path, so use the inverse element ...
POPOQQQ linear sieve Inverse element It's amazing, ......>_< Orzorz.
1 /**************************************************************2 problem:40113 User:tunix4 language:c++5 result:accepted6 time:784 Ms7 memory:10648 KB8 ****************************************************************/9 Ten //huce #7 A One#include <vector> A#include <cstdio> -#include <cstdlib> -#include <cstring> the#include <iostream> -#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) - #defineF (i,j,n) for (int i=j;i<=n;++i) + #defineD (i,j,n) for (int i=j;i>=n;--i) - using namespacestd; + A intGetint () { at intv=0, sign=1;CharCh=GetChar (); - while(ch<'0'|| Ch>'9') {if(ch=='-') sign=-1; Ch=GetChar ();} - while(ch>='0'&&ch<='9') {v=v*Ten+ch-'0'; Ch=GetChar ();} - returnv*Sign ; - } -typedefLong LongLL; in Const intn=200010, p=1e9+7, inf=~0u>>2; - /*******************template********************/ to intto[n<<1],next[n<<1],head[n],cnt; + voidAddintXinty) { -To[++cnt]=y; NEXT[CNT]=HEAD[X]; head[x]=CNT; the } * intN,m,s,t,du[n],inch[N]; $LL inv[n],f[n],ans=1;Panax Notoginseng voidLinear_shaker () { - inti; the for(inv[1]=1, i=2; i<=m+1; i++) +inv[i]= (p-p/i) *inv[p%i]%P; A } the intQ[n]; + voidTpsort () { - intL=0, r=-1; $f[t]=ans; $F (I,1, N)if(!du[i]) q[++r]=i; - while(l<=S) { - intx=q[l++]; theF[x]= (F[x]*inv[du[x])%P; - for(intI=head[x];i;i=Next[i]) {Wuyi(F[to[i]]+=f[x])%=P; the if(!--inch[To[i]]) q[++r]=To[i]; - } Wu } - } About intMain () { $ #ifndef Online_judge -Freopen ("a.in","R", stdin); - //freopen ("Output.txt", "w", stdout); - #endif AN=getint (); M=getint (); S=getint (); t=getint (); + Linear_shaker (); the intx, y; -F (I,1, M) { $X=getint (); y=getint (); the Add (x, y); the inch[y]++; du[y]++; the } thedu[t]++; -F (I,2, N) ans= (Ans*du[i])%P; in if(t==1){ theprintf"%lld\n", ans); the}Else{ About Tpsort (); theprintf"%lld\n", (ans-f[s]+p)%P); the } the return 0; +}
View Code 4011: [HNOI2015] Fall Memory Maple sound time limit:10 sec memory limit:512 M B
submit:133 solved:64
[Submit][status][discuss] Description "Problem description" may assume that there are n points on the Maple Leaf, the number of the acupoints is 1 ~ N. There are several threads connected to these acupoints. The acupoints and veins form a direction-free graph-called the choroid (Example 1), the point number makes the Acupoint 1 does not connect to its vein from other acupoints, namely the acupoints 1 has the link to go out the vein; from the above story, this has a tree-shaped graph, which is a tree with all n points at the point 1 root --Called the choroid tree (example 2 and Figure 3 give the tree is a sub-graph of the context graph given in Figure 1); It is noteworthy that the choroid tree scheme in the context diagram may have many possibilities, examples 2 and 3 are the 1 choroid tree Scenarios for the context graph given in figure two. The formal definition of the choroid tree is: With the point R as the root of the choroid tree is composed of all n points on the Maple Leaf and n-1, there is no ring in the choroid tree, there is no link from a point to its own context, and for each acupoint s on the Maple Leaf, there is a unique context within the choroid path, so from the point R Go along this path to reach the acupoints. Now add a different context to the context (note: Connecting 2 acupoints But the direction of the different contexts is different, such as from the point 3 to 4 of the context and from 4 to 3 of the context is a different context, therefore, figure 1 can not be added from 3 to 4 of the context, but can be added from 4 to 3 of the context, this new context can be From one point to the other (for example, in Figure 1 you can add a context from 4 to 4). The new context, which is added to the original context diagram, may appear in the context of the loop. Please find out the number of the choroid tree with Acupoint 1 as the root of the new context after adding this context. Because there may be too many scenarios, output the results of the scenario number 1,000,000,007 modulo. Input
The first line of the input file contains four integers n, m, x, and Y, which in turn represent the number of points on the Maple Leaf, the Pulse
The number of contacts, and the context to be added is from the point x to the acupoints y. Next m line, two integers per line, separated by a space, representing a context. The two integers of line I are UI and VI, representing the context of article I from the point UI connected to the Acupoint VI. Output
The output line, in order to add a vein from the point x connected to the acupoints y, the maple leaf on the root of the Acupoint 1
The result of the scheme number of the network tree to 1,000,000,007 modulo. Sample Input4 4 4 3
1 2
1 3
2 4
3 2Sample Output3HINT
For all test data, 1 <= n <= 100000,n-1 <= m <= min (200000, n (n–1)/2),
1 <= x, Y, UI, Vi <= N.
Source [Submit] [Status] [Discuss]
"Bzoj" "4011" "HNOI2015" Fall Memory Maple Sound