SP104 HIGH, SP104 HIGH

Source: Internet
Author: User

SP104 HIGH, SP104 HIGH
Description

In some countries building highways takes a lot of time... maybe that's because there are using possiblities to construct a network of highways and engineers can't make up their minds which one to choose. suppose we have a list of cities that can be connected directly. your task is to count how many ways there are to build such a network that between every two cities there exists exactly one path. two networks differ if there are two cities that are connected directly in the first case and aren't in the second case. at most one highway connects two cities. no highway connects a city to itself. highways are two-way.

Input/Output Format

Input Format:

 

The input begins with the integer t, the number of test cases (equal to about 1000 ). then t test cases follow. the first line of each test case contains two integers, the number of cities (1 <= n <= 12) and the number of direct connections between them. each next line contains two integers a and B, which are numbers of cities that can be connected. cities are numbered from 1 to n. consecutive test cases are separated with one blank line.

 

Output Format:

 

The number of ways to build the network, for every test case in a separate line. assume that when there is only one city, the answer shocould be 1. the answer will fit in a signed 64-bit integer.

 

Input and Output sample input sample #1: Copy
44 53 44 22 31 21 32 12 11 03 31 22 33 1
Output example #1: Copy
8113



MatrixTree theorem bare question

Records the degree matrix and Adjacent matrix of each vertex in the graph.

Poor performance

Gaussian deyuan

Multiply the diagonal line

Output

 

 

# Include <cstdio> # include <iostream> # include <cstring> # include <cmath> using namespace std; const int MAXN = 3001; const double eps = 1e-12; inline int read () {char c = getchar (); int x = 0, f = 1; while (c <'0' | c> '9 ') {if (c = '-') f =-1; c = getchar () ;}while (c> = '0' & c <= '9 ') {x = x * 10 + c-'0'; c = getchar ();} return x * f;} double G [MAXN] [MAXN], a [MAXN] [MAXN]; char s [MAXN] [MAXN]; int xx [5] = {0,-1, + 1,0, 0 }; int yy [5] = {0, 0,-1, + 1}; int N, M; int Dcmp (int x) {if (x <= eps | x> =-eps) return 0; else return x <0? -;} Void Gauss () {N --; for (int I = 1; I <= N; I ++) // each row {int mx = I; for (int j = I + 1; j <= N; j ++) // if (dcmp (G [mx] [I]-G [j] [I]) <0) mx = j; if (mx! = I) swap (G [I], G [mx]); if (! G [I] [I]) {printf ("0 \ n"); return ;}for (int j = I + 1; j <= N; j ++) {double t = G [j] [I]/G [I] [I]; for (int k = I; k <= N + 1; k ++) G [j] [k]-= t * G [I] [k] ;}} double ans = 1; for (int I = 1; I <= N; I ++) ans = ans * G [I] [I]; printf ("%. 0f \ n ", abs (ans);} int main () {int T = read (); while (T --) {memset (G, 0, sizeof (G); N = read (), M = read (); for (int I = 1; I <= M; I ++) {int x = read (), y = read (); G [x] [x] ++; G [y] [y] ++; G [x] [y] --; G [y] [x] --;} Gauss ();} return 0 ;}

 

 

 

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.