您的位置:首页 > 其它

2701: Party 排列组合问题

2010-11-01 13:09 351 查看



2701: Party

ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE

1s8192K323Standard
Go, go, go, it's party time !!! A great many of guests are invited. Guests are numbered from 1 to N. To make the party more joyful, every 3 guests, who are friends to each other, or strangers to each other, will be asked to make a show together. For some preparation reasons, could you please tell me how many shows shall be performed?

Input

Each test case begins with two integers N, M (N <= 1000, M <= 10000). Then M lines follows, each of them will contain two integers a and b, telling that a and b are friends. None of the friend relations will appear more than once in each test case. The inputs terminates when N = M = 0.

Output

For each test case, print the number of shows to be performed in a single line.

Sample Input

3 1
1 2

3 3
1 2
2 3
1 3

5 3
1 2
2 3
1 3

0 0

Sample Output

0
1
4

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int _link[10000];//_link[i]表示i认识多少人
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)==2&&n)
{
memset(_link,0,sizeof(_link));
while(m--)
{
int a,b;scanf("%d%d",&a,&b);
_link[a]++,_link[b]++;
}
int res=0;//只有两个认识
for(int i=1;i<=n;i++)
{
res+=_link[i]*(n-_link[i]-1);//减去本身
}
res>>=1;//减去相同情况
int cnt=n*(n-1)*(n-2)/6;//总情况
printf("%d/n",cnt-res);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: