uva10766 Organising the Organisation(生成树计数模板)

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 that wishes to remain anonymous, and I am currently facing a small problem for which I need a skilled programmer's help.


Currently, our company is divided into several more or less independent divisions. In order to make our business more efficient, these need to be organised in a hierarchy, indicating which divisions are in charge of other divisions. For instance, if there are 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 be at the top of the hierarchy, but the relative importance of the remaining divisions is not determined, so in Figure 1 above, division C and D could equally well have switched places so that C was in charge over division D. One complication, however, is that it may be impossible to get some divisions to cooperate with each other, and in such a case, neither of these divisions can be directly in charge of the other. For instance, if in the example above A and D are unable to cooperate, Figure 1 is not a valid way to organise the company.

In general, there can of course be many different ways to organise the organisation, and thus it is desirable to find the best one (for instance, it is not a good idea to let the programming people be in charge of the marketing people). This job, however, is way too complicated for you, and your job is simply to help us find out how much to pay the consultant 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 is, which is why you have to count exactly how many different ways there are 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 50, terminated by end-of-file. Each test cases begins with three integers n, m, k (1 ≤ n ≤ 50, 0 ≤ m ≤ 1500, 1 ≤ k ≤ n)n denotes the number of divisions in the company (for convenience, the divisions are numbered from 1 to n), and k indicates which division is the Central Management division. This is followed by m lines, each containing two integers 1 ≤ i, j ≤ n, indicating that division i and division jcannot cooperate (thus, i cannot be directly in charge of j and j cannot be directly in charge of i). You may assume that i and j are always different.

Output

For each test case, print the number of possible ways to organise the company on a line by itself. This number will be at least 1 and at 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

 



Problem setter: Per Austrin

/*
无向图,不用管根节点的位置,输入的是不联通的点,反向处理一下就好。。
这个模板可以不用double,先copy上,明天起来再理解吧。。
Time:2015-2-1 1:32
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int MAX=55;
int g[MAX][MAX];
LL a[MAX][MAX];
LL Det(int n){
    LL ret=1;
    int sign=0;
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            while(a[j][i]){
                LL t=a[i][i]/a[j][i];
                for(int k=i;k<=n;k++)
                    a[i][k]=(a[i][k]-a[j][k]*t);
                for(int k=i;k<=n;k++)
                    swap(a[i][k],a[j][k]);
                sign++;
            }
        }
        if(a[i][i]==0) return 0;

        ret*=a[i][i];
    }
    if(sign&1) ret=-ret;

    return ret;
}
int main(){
    int n,m,k;
    int u,v;
    while(scanf("%d%d%d",&n,&m,&k)!=EOF){//无向图生成树个数与根节点无关
        memset(a,0,sizeof(a));
        memset(g,0,sizeof(g));
        for(int i=1;i<=m;i++){
            scanf("%d%d",&u,&v);
           // u--;v--;
            g[v][u]=g[u][v]=1;
        }
        for(int i=1;i<=n;i++){
                int d=0;
            for(int j=1;j<=n;j++){
                if(i!=j&&g[i][j]==0){
                    d++;
                    a[i][j]=-1;
                }
            }
            a[i][i]=d;
        }/*
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                printf(" %d",a[i][j]);
            }puts("");
        }*/
        printf("%lld\n",Det(n-1));
    }
return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值