2701: Party 排列组合问题

本文介绍了一个派对场景下的计算问题,需要根据受邀宾客之间的友谊关系计算可以形成的表演组合数量。通过输入宾客总数及彼此间的友谊关系,算法能够计算出所有可能的三人组合,这些组合中的成员要么彼此都是朋友,要么彼此互不相识。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值