Question: Give You n points. If the distance between the two points is less than or equal to r, you can even get an edge to survive the number of trees.
Question:
For an undirected graph G, its Kirchhoff matrix C is defined as its degree matrix D minus its adjacent matrix. Obviously, this definition satisfies the nature described just now.
With the Kirchhoff Matrix tool, we can introduce the Matrix-Tree theorem:
The matrix rules are as follows:
1. The degree of the element on the primary diagonal to this node
2. For the Element Matrix (I, j) {I! = J },
(1) If node I is connected to node j, the value of Matrix (I, j) is-k, where the k value is the number of parallel edges from node I to node j. If this graph is a simple graph, that is, if there is no parallel edge between two points, the value is-1.
(2) If node I and node j are not connected at all, the value of Matrix (I, j) is 0.
Method: For an undirected graph G, the number of spanning trees is equal to the absolute value of the determinant of any n-1 primary-child type in the Kirchhoff matrix. N-1 r, delete the new matrix of row r and column r of column C at the same time, which is expressed by Cr. Complexity: O (n ^ 3)
AC code:
# Include <iostream> # include <vector> # include <list> # include <deque> # include <queue> # include <iterator> # include <stack> # include <map> # include <set> # include <algorithm> # include <cctype> # include <cstdio> # include <cstdlib> # include <cstring> # include <string> # include <cmath> using namespace std; typedef long LL; const int N = 302; const LL mod = 10007; const int INF = 0x3f3f3f; const doub Le PI = acos (-1.0); const double eps = 1e-7; using namespace std; int a [N] [N], mp [N] [N]; int n; double r; struct node {double x, y; node () {}; node (double a, double B): x (a), y (B) {} void input () {scanf ("% lf", & x, & y);} friend node operator-(const node & a, const node & B) {return node (. x-b.x,. y-b.y);} p [N]; double dis (node a, node B) {return (. x-b.x) * (. x-b.x) +. y-b.y) * (. y-b.y);} bool love (int I, Int k, int j) {double t = (p [I]. x-p [k]. x) * (p [j]. y-p [k]. y)-(p [I]. y-p [k]. y) * (p [j]. x-p [k]. x); if (fabs (t-0)> 1e-6) return false; // t = (p [I]. x-p [k]. x) * (p [j]. x-p [k]. x) + (p [I]. y-p [k]. y) * (p [j]. y-p [k]. y); if (t> = 0) return false; // return true not in the middle of ij;} int ext_gcd (int a, int B, int & x, int & y) {int t, ret; if (! B) {x = 1, y = 0; return a;} ret = ext_gcd (B, a % B, x, y); t = x, x = y, y = t-a/B * y; return ret;} int gauss (int r, int c) {int I = 1, k, j, cnt = 1; for (j = 1; j <= c; j ++) {int id = I; for (k = I; k <= r; k ++) if (a [k] [j]> 0) {id = k; break;} if (a [id] [j]) {if (id! = I) {for (k = j; k <= c; k ++) swap (a [I] [k], a [id] [k]);} for (k = I + 1; k <= r; k ++) {if (! A [k] [j]) continue; cnt = (cnt * a [I] [j]) % mod; for (int l = c; l> = j; l --) {a [k] [l] = (a [k] [l] * a [I] [j]-a [I] [l] * a [k] [j ]) % mod; a [k] [l] = (a [k] [l] + mod) % mod;} I ++ ;}} int x, y; ext_gcd (cnt, mod, x, y); x = (x % mod + mod) % mod; // x is the reverse element of cnt for mod (I = 1; I <= r; I ++) x = (x * a [I] [I]) % mod; return (x + mod) % mod;} int main () {int t, I, j, k, cas; scanf ("% d", & t); while (t --) {scanf ("% d % lf ", & n, & r); for (I = 1; I <= n; I ++) p [I]. input (); memset (a, 0, s Izeof (a); memset (mp, 0, sizeof (mp); double rr = r * r; for (I = 1; I <= n; I ++) for (j = I + 1; j <= n; j ++) {if (dis (p [I], p [j])> rr) continue; int flag = 1; for (k = 1; k <= n; k ++) {if (I = k | j = k) continue; // here, the operator overload is used, and the result times out. if it is changed to your own definition, if (love (I, k, j) is used )) // k is in the middle of the ij line segment {flag = 0; break ;}} if (flag) {mp [I] [j] = mp [j] [I] = 1; a [I] [j] --; a [j] [I] --; a [I] [I] ++; a [j] [j] ++ ;}} /* cout <endl; for (I = 1; I <= n; I ++) {for (j = 1; j <= n; j ++) printf ("% D", mp [I] [j]); cout <endl ;}cout <endl; for (I = 1; I <= n; I ++) {for (j = 1; j <= n; j ++) printf ("% d", a [I] [j]); cout <endl ;} */int xh = gauss (n-1, n-1); if (xh = 0) puts ("-1"); else printf ("% d \ n ", xh);} return 0 ;} /* 3 3 2-1 0 0 1 1 0 3 2-1 0 0 0 1 0 3 1-1 0 0 1 0 */# include <iostream> # include <vector> # include <list> # include <deque> # include <queue> # include <iterator> # include <stack> # include <map> # inclu De <set> # include <algorithm> # include <cctype> # include <cstdio> # include <cstdlib> # include <cstring> # include <string> # include <cmath> using namespace std; typedef long LL; const int N = 302; const LL mod = 10007; const int INF = 0x3f3f3f; const double PI = acos (-1.0); const double eps = 1e-7; using namespace std; int a [N] [N], mp [N] [N]; int n; double r; struct node {double x, y; node () {}; node (double a, double B): x (), Y (B) {} void input () {scanf ("% lf", & x, & y);} friend node operator-(const node &, const node & B) {return node (. x-b.x,. y-b.y);} p [N]; double dis (node a, node B) {return (. x-b.x) * (. x-b.x) +. y-b.y) * (. y-b.y);} bool love (int I, int k, int j) {double t = (p [I]. x-p [k]. x) * (p [j]. y-p [k]. y)-(p [I]. y-p [k]. y) * (p [j]. x-p [k]. x); if (fabs (t-0)> 1e-6) return false; // t = (p [I]. x-p [k]. x) * (p [j]. x-p [k]. x) + (p [I]. Y-p [k]. y) * (p [j]. y-p [k]. y); if (t> = 0) return false; // return true not in the middle of ij;} int ext_gcd (int a, int B, int & x, int & y) {int t, ret; if (! B) {x = 1, y = 0; return a;} ret = ext_gcd (B, a % B, x, y); t = x, x = y, y = t-a/B * y; return ret;} int gauss (int r, int c) {int I = 1, k, j, cnt = 1; for (j = 1; j <= c; j ++) {int id = I; for (k = I; k <= r; k ++) if (a [k] [j]> 0) {id = k; break;} if (a [id] [j]) {if (id! = I) {for (k = j; k <= c; k ++) swap (a [I] [k], a [id] [k]);} for (k = I + 1; k <= r; k ++) {if (! A [k] [j]) continue; cnt = (cnt * a [I] [j]) % mod; for (int l = c; l> = j; l --) {a [k] [l] = (a [k] [l] * a [I] [j]-a [I] [l] * a [k] [j ]) % mod; a [k] [l] = (a [k] [l] + mod) % mod;} I ++ ;}} int x, y; ext_gcd (cnt, mod, x, y); x = (x % mod + mod) % mod; // x is the reverse element of cnt for mod (I = 1; I <= r; I ++) x = (x * a [I] [I]) % mod; return (x + mod) % mod;} int main () {int t, I, j, k, cas; scanf ("% d", & t); while (t --) {scanf ("% d % lf ", & n, & r); for (I = 1; I <= n; I ++) p [I]. input (); memset (a, 0, sizeof (a); memset (mp, 0, sizeof (mp); double rr = r * r; for (I = 1; I <= n; I ++) for (j = I + 1; j <= n; j ++) {if (dis (p [I], p [j])> rr) continue; int flag = 1; for (k = 1; k <= n; k ++) {if (I = k | j = k) continue; // operator overload is used at this point, and the result times out, if (love (I, k, j) // k is defined as if (love (I, k, j) in the middle of the ij line segment {flag = 0; break ;}} if (flag) {mp [I] [j] = mp [j] [I] = 1; a [I] [j] --; a [j] [I] --; a [I] [I] ++; a [j] [j] ++ ;}}/* cout <endl; for (I = 1; I <= n; I ++) {for (j = 1; j <= n; j ++) printf ("% d", mp [I] [j]); cout <endl ;}cout <endl; for (I = 1; I <= n; I ++) {for (j = 1; j <= n; j ++) printf ("% d", a [I] [j]); cout <endl;} */int xh = Gaussian (n-1, n-1 ); if (xh = 0) puts ("-1"); else printf ("% d \ n", xh) ;}return 0 ;} /* 33 2-1 00 11 03 2-1 00 01 03 1-1 00 11 0 */