CSU 1805 three capitals (Matrix tree theorem +best theorem)

Source: Internet
Author: User

http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1805

Test instructions

A and B have a side, a and G have a B-bar, and B and G have a C-side. Now go through all the edges from point a, and then go back to point a, and ask how many ways there are.

Ideas:

16 Hunan Province, the title of the problem is to find the number of Euro-loop, and the count of spanning tree has a certain connection.

First of all, the magic of the best theorem, which is what the devil theorem, anyway, nothing to find out about the theorem of the article ...

$ec (g) =t_s (g) \cdot deg (s)! \cdot \prod_{v\in v,\ v\ne s} (deg (v)-1)!,\ t_s (G): =$ number of outward trees with s root.

The number of outward trees in the graph is almost the same as the number of spanning trees of the graph, in short, The Matrix tree theorem, but a little bit different place.

The structure of the Kirchhoff matrix is not quite the same, after all, one is an no-map, and one is a graph of the direction:

The degree matrix in the no-map is the degree of each vertex, and the degree matrix in the graph is the degree of each vertex.

The adjacency matrix is the number of sides of the u->v, which is similar to the non-graph.

Then there is the calculation of the matrix:

Number of spanning trees for an n-1 graph = values of arbitrary-order master

Number of outward trees of the graph = the value of the principal of the order in which the root node is removed

Note that this topic also need to calculate the number of combinations, for example, A and b there is a side, then I can choose the x edge for the edge, then the remaining a-x edge for the out side, in this process will have a different choice method. The total is $c (a,x) *c (b,y) *c (c,z) $.

1#include <iostream>2#include <algorithm>3#include <cstring>4#include <cstdio>5#include <sstream>6#include <vector>7#include <stack>8#include <queue>9#include <cmath>Ten#include <map> One#include <Set> A using namespacestd; -typedefLong Longll; -typedef pair<int,ll>PLL; the Const intINF =0x3f3f3f3f; - Const intmaxn= -+5; - Constll mod=1e9+7; -  + inta,b,c; -ll f[100005]; +ll a[5][5]; A  at voidInit () - { -f[0]=1; -      for(intI=1; i<=100005; i++) f[i]=f[i-1]*i%MoD; - } -  in ll Qpow (ll a,ll N) - { toll ans=1; +      while(n) -     { the         if(n&1) ans=ans*a%MoD; *a=a*a%MoD; $n>>=1;Panax Notoginseng     } -     returnans; the } +  A ll C (ll n,ll m) the { +     return(F[n]*qpow (f[m],mod-2)%mod) *qpow (f[n-m],mod-2)%MoD; - } $  $ ll Calc () - { -     return(a[1][1]*a[2][2]%mod-a[1][2]*a[2][1]%MOD+MOD)%MoD; the } - Wuyi intMain () the { -     //freopen ("In.txt", "R", stdin); Wu init (); -      while(~SCANF ("%d%d%d",&a,&b,&c)) About     { $         if((A+C) &1|| (a+b) &1|| (B+C) &1) {puts ("0");Continue;} -ll ans=0; -          for(intI=0; i<=a;i++)//enumerates the number of edges of a a->b -         { Amemset (A,0,sizeof(A)); +a[0][0]= (A+B)/2; thea[1][1]= (A+C)/2; -a[2][2]= (B+C)/2; $a[0][1]=-i; thea[1][0]=-(A-i); thea[0][2]=-(a[0][0]-i); thea[2][0]=-(b+a[0][2]); thea[1][2]=-(a[1][1]+a[1][0]); -a[2][1]=-(c+a[1][2]); in             if(a[0][2]>0|| a[2][0]>0|| a[1][2]>0|| a[2][1]>0)Continue; the  thell res= (C (a,i) *c (c,-a[1][2])%mod) *c (b,-a[0][2])%MoD; About  theRes= (Res*calc ())%MoD; the              for(intI=1;i<3; i++) res=res*f[a[i][i]-1]%MoD; theres=res*f[a[0][0]]%MoD; +ans= (ans+res)%MoD; -         } theprintf"%lld\n", ans);Bayi     } the     return 0; the}

CSU 1805 three capitals (Matrix tree theorem +best theorem)

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.