国产探花免费观看_亚洲丰满少妇自慰呻吟_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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 牡丹江市| 宾阳县| 苍山县| 鞍山市| 信阳市| 中宁县| 浏阳市| 临桂县| 吴江市| 额尔古纳市| 江孜县| 乌兰浩特市| 沾化县| 凤山县| 丰都县| 紫阳县| 连平县| 上饶市| 大埔县| 中卫市| 夏津县| 旺苍县| 定安县| 张家川| 榆中县| 和平县| 蒲江县| 舒城县| 揭阳市| 广水市| 探索| 夏河县| 溧阳市| 衡水市| 日土县| 栖霞市| 额济纳旗| 敦化市| 嘉荫县| 荥阳市| 漳州市|