Spanning count UVA 10766

1  // this question that Italy: first of all up between each point, and m include not reachable, the program obtains the most spanning tree;
 2  // K variable is useless.
3  @ formula: ans = Matrix matrix - matrix built edge;
 4  // matrix if i == j when built usually the same as defined in the matrix side up matrix 
. 5 #include <stdio.h>
 . 6 #include < String .h>
 . 7 #include <math.h>
 . 8 #include <algorithm>
 . 9  the using  namespace STD;
 10  #define INF 0x3f3f3f3f
 . 11  #define LL Long Long int
 12 is  const  int MAXN = 55 ;
 13 is  LL A [MAXN] [ MAXN];
 14 LL B[MAXN][MAXN];
15 LL determinant(int n)
16 {
17     LL res=1;
18     for(int i=1;i<=n;i++){
19         if(!B[i][i]){
20             bool flag=false;
21             for(int j=i+1;j<=n;j++){
22                 if(B[j][i]){
23                     flag=true;
24                     for(int k=i;k<n;k++){
25                         swap(B[i][k],B[j][k]);
26                     }
27                     res=-res;
28                     break;
29                 }
30             }
31             if(!flag)
32             return 0;
33         }
34         for(int j=i+1;j<=n;j++){
35             while(B[j][i]){
36                 LL t=B[i][i]/B[j][i];
37                 for(int k=i;k<=n;k++){
38                     B[i][k]=B[i][k]-t*B[j][k];
39                     swap(B[i][k],B[j][k]);
40                 }
41                 res=-res;
42             }
43         }
44         res*=B[i][i];
45     }
46     return res;
47 }
48 int main()
49 {
50     int n,m,k;
51     while(~scanf("%d%d%d",&n,&m,&k))//The k no eggs used, can completely ignore 
52 is      {   
 53 is          Memset (A, 0 , the sizeof (A));
 54 is          Memset (B, 0 , the sizeof (B));
 55          for ( int I = . 1 ; I <= m; I ++ ) {
 56 is              int A, B;
 57 is              Scanf ( " % D% D " , & A, & B);
 58              A [A] [B] = A [B] [A] = . 1 ;
 59          }
 60          for ( int = I . 1 ; I <= n-; I ++ ) {
61 is              for ( int J = . 1 ; J <= n-; J ++ ) {
 62 is                  IF (! I = J &&! A [I] [J]) {
 63 is                      B [I] [I] ++ ;
 64                      B [I] [ J] = - . 1 ; // subtracting the adjacency matrix 
65                  }
 66              }
 67          }
 68          n-= N- . 1 ;
 69          LL = ANS determinant (n-); 
 70          the printf ( " % LLD \ n- " , ANS);
 71 is      }
 72      return  0;
73 }

 

Guess you like

Origin www.cnblogs.com/pangbi/p/11701270.html