A ZZ check information received lessons -
- An algorithm is not going to have a Chinese name check was originally called (╯ `□ ') ╯(┻━┻
- Unless you want to see the proof or write a blog, or something, you do not have to go to Wikipedia OR papers. After all, to see some kind of mathematical knowledge, headache <(_ _)>
- To see Question title ◑﹏◐ do, otherwise you will find one (think) very difficult problem, and then self-closing stop four defense up
- Do not stay up late U • S Factory • * U
Transfer gate -----> Los Valley / bzoj
See details Code
. 1 #include <CString> 2 #include <the iostream> . 3 #include <cstdio> . 4 #include <algorithm> . 5 the using namespace STD; . 6 / * . 7 general idea ---- generating first to see whether the minimum spanning tree 8 followed to find weight is replaced minimum spanning tree can enumerate each one of . 9 put the weight is reduced in the other points. Since we do not care what is the other side, so long as we know whether China Unicom to 10 and then combined with matrix tree theorem and multiplication principle evaluated 11 pre-knowledge ---- 1. The minimum spanning 12 2. Matrix Tree Theorem 13 3. the basic idea of the block (in fact, not necessary QAQ, may now be appreciated) 14 4. the principle of multiplier 15 (crossed) 5. mathematics and does not count the number of error (crossed) 16 9 pounds 15 pence . 17 * / 18 is namespace the_Death { . 19 const int MAXN = 1E3 + . 5 , MAXN = 1E3 + . 5 , MOD = 31011 ; 20 is int n-, m, TOT, FA [MAXN], A [MAXN] [MAXN] , del [MAXN], Val [MAXN]; 21 is // Val [MAXN] -> refers to the number of unique values are 22 is // del [MAXN] -> refers to the condensing point of reconstruction in FIG 23 @ a [maxn] [maxn] - > Kirchhoff matrix 24 struct Ziji { 25 int X, Y, Z; 26 is BOOL operator <( const Ziji B &) const{ Return Z < BZ;} 27 #define X (I) Mn [I] .x 28 #define Y (I) Mn [I] .y 29 #define Z (I) Mn [I] .Z 30 #define U (I) Tree [I] .x 31 is #define V (I) Tree [I] .y 32 #define W (I) Tree [I] .Z 33 is } Mn [MAXN], Tree [MAXN]; 34 is // mn [maxn] -> is previously stored in the array of FIG. 35 // tree [MAXN] -> is a diagram showing the configuration point of minimum spanning tree 36 inline int Find ( int X) { return FA [X] == X? X: Find (FA [X]);} 37 [ inline void IT () { for (Register int I = . 1 ; I <= n-; I ++) FA [I] = I;} 38 is inline void the Add ( int X, int Y) { 39 --a [X] [Y ], - A [Y] [X], A ++ [X] [X], ++ A [Y] [Y]; 40 // configured Kirchhoff matrix 41 is } 42 is inline void Merge ( int X , int Y) {FA [Find (X)] = Find (Y);} 43 is inline int Gauss ( int n-) { 44 is // use division removed cytometry Gaussian elimination 45 // reason to use divide removed, in order to maintain the accuracy of only 46 is int ANS = . 1 ; 47 for (Register int I = . 1 ; I <= n-; I ++ ) { 48 for (Register int K = I + . 1 ; K <= n-; K ++ ) { 49 the while (A [K] [I]) { 50 int D = A [I] [I] / A [K] [I]; 51 is for (Register int J = I; J <= n- ; J ++ ) 52 is A [I] [J] = (A [I] [J] -1LL * D * A [K] [J]% MOD + MOD)% MOD; 53 is the swap (A [I], A [ k]), ans = -ANS; 54 is // exchange line, determinant change 55 } 56 is } 57 is ANS = 1LL ANS * A * [I] [I]% MOD, ANS = (ANS + MOD)% MOD; 58 // multiplication principle of total 59 } 60 return ANS; 61 is } 62 is inline BOOL Kruskal () { 63 is Sort (Tree + . 1 , Tree + . 1 + m); IT (); 64 int CNT = 0 ; 65 for (Register int I = . 1 ; I <= m; I ++) { 66 int the root = Find (U (I)), the root1 = Find (V (I)); 67 IF (the root == the root1) Continue ; 68 FA [the root] = the root1, Mn [CNT ++] = Tree [I]; 69 // put into use point mn [maxn] to the 70 IF (W (I) = Val [TOT]!) Val [TOT ++] = W (I); 71 is // record Unique right point 72 } 73 is return CNT N- == . 1 ; 74 } 75 inline void addedge ( int V) { 76 for (Register int I =. 1 ; I <n-&& Z (I) = V;! I ++ ) Merge (X (I), Y (I)); 77 for (Register int I = N- . 1 ; I && Z (I)! = V; i-- ) Merge (X (I), Y (I)); 78 // bidirectional updated new tree Unicom NOTICE: the DO YOU the MUST the LIKE THIS the iT 79 80 } 81 inline int getBlock () { 82 // get number of points after which it is retracted points 83 int BIo = 0 ; 84 for (Register int I = . 1 ; I <= n-; I ++ ) 85 IF (Find (I) == I) del [I] ++ = BIo; 86 for(Register int I = . 1 ; I <= n-; I ++) del [I] = del [Find (I)]; 87 // operation is similar to the block 88 return BIo; 89 } 90 inline void the rebuild ( int V) { 91 // every time to find a right side, side to see if he has several transformation, we must each time the rebuild 92 Memset (a, 0 , the sizeof (a)); 93 for (Register int I = . 1 ; I <= m; I ++ ) 94 IF (W (I) == V) the Add (del [U (I)], del [V (I)]); 95 //If found, then you record configured Kirchhoff matrix 96 } 97 int main () { 98 Scanf ( " % D% D " , & n-, & m); int ANS = . 1 ; 99 for (Register int I = . 1 ; I <= m; I ++ ) 100 Scanf ( " % D% D% D " , & U (I), & V (I), & W (I)); 101 IF (! Kruskal ()) {the puts ( " 0 " ); System ( " PAUSE " ); return 0 ;} 102 for(register int i=1;i<=tot;i++){ 103 it();addedge(val[i]);int blo=getblock(); 104 rebuild(val[i]);ans=1ll*ans*gauss(blo-1)%mod; 105 } 106 printf("%d\n",ans);system("pause");return 0; 107 } 108 } 109 int main(){ 110 the_Death::main();return 0; 111 }