UVA 10766 Organising the organisation spanning tree count

Source: Internet
Author: User


Spanning Tree count: Kirchhoff's matrix tree theorem


Kirchhoff matrix of the graph : the degree of each point on the diagonal, if there is an edge between IJ, the matrix ij is-1

The number of spanning trees for an n-1 graph is: the absolute value of the determinant of any one of the first-order masters.



UVA-10766Organising the organisation
Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld &%llu

Submit Status

Description

Problem H
Organising the organisation

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 the hierarchy, but the relative importance of the remaining divisions are not determined, so in Figure 1 above, Division C and 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 manydifferent 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
        

3


Problem Setter:per Austrin

Source

Root:: Prominent problemsetters:: Per Austrin
Root:: AOAPC ii:beginning algorithm Contests (Second Edition) (Rujia Liu):: Chapter 12. Advanced Topics:: Extra

Submit Status




/* ***********************************************author:ckbosscreated time:2015 April 28 Tuesday 16:20 58 seconds file Name : uva10766.cpp************************************************ * * #include <iostream> #include <cstdio># Include <cstring> #include <algorithm> #include <string> #include <cmath> #include <cstdlib > #include <vector> #include <queue> #include <set> #include <map>using namespace Std;typedef Long double ld;const LD eps=1e-10;const int maxn=60;int sgn (ld x) {if (Fabs (x) <eps) return 0; if (x<0) return-1; retur n 1;} LD B[MAXN][MAXN]; LD det (LD a[][maxn],int n) {int sign=0;int i,j,k; LD ret=1;for (i=0;i<n;i++) for (j=0;j<n;j++) b[i][j]=a[i][j];for (i=0;i<n;i++) {if (SGN (b[i][i)) ==0) {for (j=i+ 1;j<n;j++) if (SGN (B[j][i])!=0) break;if (j==n) return 0;for (k=i;k<n;k++) swap (b[i][k],b[j][k]); sign++;} Ret*=b[i][i];for (k=i+1;k<n;k++) b[i][k]/=b[i][i];for (j=i+1;j<n;j++) for (k=i+1;k<n;k++) b[j][k]-=b[j][i]* B[I][K];} if (sign&1) ret=-ret;return ret;} BOOL G[MAXN][MAXN];    LD a[maxn][maxn];int N,m,k;int Main () {//freopen ("In.txt", "R", stdin); Freopen ("OUT.txt", "w", stdout), while (scanf ("%d%d%d", &n,&m,&k)!=eof) {memset (g,true,sizeof (g)); memset (A,0,sizeof (a)); for (int i=0;i<m;i++) {int x, Y, scanf ("%d%d", &x,&y); x--; y--;g[x][y]=g[y][x]=false;} for (int i=0;i<n;i++) {for (int j=i+1;j<n;j++) {if (g[i][j]==true) {a[i][i]++; a[j][j]++;a[i][j]=-1; a[j][i]=-1;}}}        LD Ans=det (a,n-1);p rintf ("%.0lf\n", ans); return 0;}


UVA 10766 Organising the organisation spanning tree count

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.