国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

SPOJ HIGH Highways

2019-11-08 20:17:44
字體:
來源:轉載
供稿:網友

In some countries building highways takes a lot of time... Maybe that's because there are many 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

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

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 should be 1. The answer will fit in a signed 64-bit integer.

Example

Sample input:44 53 44 22 31 21 32 12 11 03 31 22 33 1Sample output:8113~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~行列式生成樹計數~神奇的算法~快速求出生成樹個數~對于每個點,a[i][i]為i點的度數,如果i與j之間有邊相連,則a[i][j]=-1,然后行列式求n-1矩陣的值即可~輸出一定要用%0.0lf。
#include<cstdio>#include<cstring>#include<iostream>using namespace std;#define zero(u) (u>0 ? u:-u)<1e-15int t,n,m,x,y;double a[13][13],c[13][13];bool b[13][13];double cal(){	int sign=0,i,j,k;double ans=1;	for(i=1;i<=n;i++)	  for(j=1;j<=n;j++) c[i][j]=a[i][j];	for(i=1;i<=n;i++)	{		if(zero(c[i][i]))		{			for(j=i+1;j<=n;j++) if(!zero(c[j][i])) break;		  	if(j==n+1) return 0;			for(k=i;k<=n;k++) swap(c[i][k],c[j][k]);			sign++;		}		ans*=c[i][i];		for(k=i+1;k<=n;k++) c[i][k]/=c[i][i];		for(j=i+1;j<=n;j++)		  for(k=i+1;k<=n;k++) c[j][k]-=c[j][i]*c[i][k];	}	if(sign&1) ans=-ans;	return ans;}int main(){	scanf("%d",&t);	while(t--)	{		scanf("%d%d",&n,&m);		memset(a,0,sizeof(a));		memset(b,0,sizeof(b));		while(m--)		{			scanf("%d%d",&x,&y);b[x][y]=b[y][x]=1;		}		for(int i=1;i<=n;i++)		  for(int j=1;j<=n;j++) if(b[i][j]) a[i][i]+=1;		for(int i=1;i<=n;i++)		  for(int j=1;j<=n;j++) if(b[i][j]) a[i][j]=-1;		n--;PRintf("%0.0lf/n",cal());	}	return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 高碑店市| 延吉市| 甘谷县| 无极县| 武功县| 广元市| 屏东市| 招远市| 海原县| 长治市| 镶黄旗| 开鲁县| 闵行区| 集安市| 乌拉特中旗| 吕梁市| 颍上县| 天镇县| 登封市| 清丰县| 会昌县| 云林县| 贵定县| 车致| 谷城县| 平顶山市| 清水县| 南江县| 松滋市| 鄂托克旗| 体育| 黔南| 德保县| 华亭县| 常宁市| 昔阳县| 太保市| 岢岚县| 大兴区| 商洛市| 海晏县|