Friends----暴力枚举

来源:互联网 发布:free mobile java在线 编辑:程序博客网 时间:2024/06/06 01:38

Friends

Time Limit: 2 Seconds      Memory Limit: 65536 KB

Alice lives in the country where people like to make friends. The friendship is bidirectional and if any two person have no less than k friends in common, they will become friends in several days. Currently, there are totally n people in the country, and m friendship among them. Assume that any new friendship is made only when they have sufficient friends in common mentioned above, you are to tell how many new friendship are made after a sufficiently long time.

Input

There are multiple test cases.

The first lien of the input contains an integer T (about 100) indicating the number of test cases. Then T cases follow. For each case, the first line contains three integers n, m, k (1 ≤ n ≤ 100, 0 ≤ m ≤n×(n-1)/2, 0 ≤ k ≤ n, there will be no duplicated friendship) followed by m lines showing the current friendship. The ith friendship contains two integers ui, vi (0 ≤ ui, vi < nui ≠ vi) indicating there is friendship between person ui and vi.

Note: The edges in test data are generated randomly.

Output

For each case, print one line containing the answer.

Sample Input

34 4 20 10 21 32 35 5 20 11 22 33 44 05 6 20 11 22 33 44 02 0

Sample Output

204


Author: ZHUANG, Junyuan
Contest: The 10th Zhejiang Provincial Collegiate Programming Contest

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3710


这个题是我傻了,我把它想难了,题目的意思是说告诉你几个确定的关系,问你能再推出来几个确定的关系。

暴力枚举就好。。

代码:

#include <cstdio>#include <cstring>#include <iostream>using namespace std;bool map1[101][101];int g[101][101];int main(){    int t;    scanf("%d",&t);    while(t--){        memset(map1,false,sizeof(map1));        int n,m,k;        scanf("%d%d%d",&n,&m,&k);        for(int i=0;i<m;i++){            int x,y;            scanf("%d%d",&x,&y);            map1[x][y]=true;            map1[y][x]=true;        }        int sum=0;        while(1){            int ans=0;            memset(g,0,sizeof(g));            for(int i=0;i<n-1;i++){                for(int j=i+1;j<n;j++){                    if(map1[i][j]&&map1[j][i])                        continue;                    for(int z=0;z<n;z++){                        if(map1[i][z]&&map1[j][z]){                            g[i][j]++;                        }                    }                    if(g[i][j]>=k){                        ans++;                        map1[i][j]=true;                        map1[j][i]=true;                    }                }            }            if(ans==0){                break;            }            sum+=ans;        }        cout<<sum<<endl;    }    return 0;}


0 0
原创粉丝点击