High-highways
In some countries building highways takes a lot of time ... Maybe that ' s because there is many possiblities to construct a network of highways and engineers can ' t do up their s which one to choose. Suppose we have a list of cities so can be connected directly. Your task is to count how many ways there be to build such a network that between every the cities there exists exactly O NE path. The networks differ if there is the cities that is connected directly in the first case and aren ' t in the second case. At the most one highway connects and cities. No Highway connects a city to itself. Highways is two-way.
Input
The input begins with the integer t and the number of test cases (equal to about 1000). Then T test cases follow. The first line of all test case contains-integers, the number of cities (1<=n<=12) and the number of direct con Nections between them. Each next line contains integers a and B, which is numbers of cities that can is connected. Cities is numbered from 1 to N. Consecutive test cases is separated with one blank line.
Output
The number of ways to build the network, for every test case in a separate line. Assume that's when there was only one city, the answer should was 1. The answer would fit in a signed 64-bit integer.
Example
Sample input:A. 1sample output:8113 ()
1#include <iostream>2#include <cstring>3#include <cstdio>4 using namespacestd;5 Const intmaxn= -;6 intc[maxn][maxn],n,m;7 8 intSolve () {9 for(intI=1; i<n;i++){Ten for(intj=i+1; j<n;j++) One while(C[j][i]) { A intr=c[i][i]/C[j][i]; - for(intk=i;k<n;k++) -c[i][k]-=c[j][k]*R; the swap (c[i],c[j]); - } - } - Long Longret=1; + for(intI=1; i<n;i++) -ret*=C[i][i]; + returnret<0?-Ret:ret; A } at - intMain () { - intT; -scanf"%d",&T); - while(t--){ -memset (C,0,sizeof(C)); inscanf"%d%d",&n,&m); - while(m--){ to intb; +scanf"%d%d",&a,&b); -c[a][a]++; c[b][b]++; thec[a][b]=c[b][a]=-1; * } $printf"%d\n", Solve ());Panax Notoginseng } - return 0; the}
10766-organising the organisation
Time limit:3.000 seconds
Input: Standard Input
Output: Standard Output
Time Limit: 2 Second
I am the chief of the Personnel division of a moderate-sized company it wishes to remain anonymous, and I am currently F Acing a small problem for which I need a skilled programmer ' s help.
Currently, we are divided to several more or less independent divisions. In order-to-make efficient, these need to be organised in a hierarchy, indicating which divisions is in Charge of other divisions. For instance, if there is four divisions a, B, C and D we could organise them as in Figure 1, with Division A controlling Divisions B and D, and Division D controlling Division C.
One of the divisions is central Management (Division A in the figure above), and should of course was at the top of th e hierarchy, but the relative importance of the remaining divisions are not determined, so in Figure 1 above, Division C an D D could equally well has switched places so that C is in charge over division D. One complication, however, is the it may are impossible to get some divisions to cooperate with each other, and in such a Case, neither of these divisions can is directly in charge of the other. For instance, if in the example above a and D were unable to cooperate, Figure 1 was not A valid a-to-organise the company .
In general, there can of course was many different ways to organise the organisation, and thus it was desirable to find the Best one (for instance, it isn't a good idea to let the programming people being in charge of the marketing people). This job, however, is-on-the-too complicated for you, and your job are simply to help us find out how much to pay the Consulta NT that we hire to find the best organisation for us. In order to determine the consultant's pay, we need to find out exactly how difficult the task was, which is so you have t o count exactly how many different ways there is to organise the organisation.
Oh, and I need the answer in five hours.
Input
The input consists of a series of test cases, at most -, terminated by End-of-file. Each test cases begins with three integersN, M, K (1≤n≤50, 0≤m≤1500, 1≤k≤n).NDenotes the number of divisions in the company (for convenience, the divisions is numbered from1ToN), andkIndicates which division is the central Management division. This was followed bymLines, each containing, integers1≤i, J≤n, indicating that divisionIand divisionJCannot cooperate (thus,ICannot is directly in charge ofJandJCannot is directly in charge ofI). Assume thatIandJis always different.
Output
For each test case, print the number of possible ways to organise the company on a line by itself. This number would be in least 1 and at the most 1015.
Sample input Output for sample input
5 5 2 3 1 3 4 4 5 1 4 5 3 4 1 1 1 4 3 0 2 |
3
8
3 |
1#include <iostream>2#include <cstring>3#include <cstdio>4 using namespacestd;5 Const intmaxn= -;6 intN,M,RT,G[MAXN][MAXN];7 Long LongC[MAXN][MAXN];8 Long LongSolve () {9 for(intI=1; i<n;i++){Ten for(intj=i+1; j<n;j++) One while(C[j][i]) { A Long Longr=c[i][i]/C[j][i]; - for(intk=i;k<n;k++) -c[i][k]-=c[j][k]*R; the swap (c[i],c[j]); - } - } - Long Longret=1; + for(intI=1; i<n;i++) -ret*=C[i][i]; + returnret<0?-Ret:ret; A } at intMain () { - while(SCANF ("%d%d%d", &n,&m,&rt) = =3){ -memset (g,-1,sizeof(G)); -memset (C,0,sizeof(C)); - while(m--){ - intb; inscanf"%d%d",&a,&b); -g[a][b]=g[b][a]=0; to } + for(intI=1; i<=n;i++) - for(intj=1; j<=n;j++) the if(i!=j&&G[i][j]) { *c[i][j]=-1; $c[i][i]+=1;Panax Notoginseng } -printf"%lld\n", Solve ()); the } + return 0; A}
Count of Spanning tree (Kirchhoff matrix): Uvaoj 10766 organising the organisation SPOJ high-highways