ZOJ 3710 Friends(暴力)

本文深入探讨了AI音视频处理领域中的视频分割与语义识别技术,介绍了视频分割的基本概念、算法及其应用,并详细阐述了语义识别在不同场景下的实现方法和挑战。

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

Description

Alice livesin the country where people like to make friends. The friendship isbidirectional and if any two person have no less than kfriends in common, they will become friends in severaldays. Currently, there are totally n peoplein the country, and m friendshipamong them. Assume that any new friendship is made only when they havesufficient friends in common mentioned above, you are to tell how many newfriendship are made after a sufficiently long time.

Input

Thereare multiple test cases.

Thefirst lien of the input contains an integer T (about 100) indicating the number of testcases. Then T casesfollow. 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 duplicatedfriendship) followed by mlines showingthe current friendship. The ith friendshipcontains two integers ui,vi (0 ≤ ui, vi < n, ui ≠ vi) indicating thereis friendship between person ui and vi.

Note: The edges in test data are generated randomly.

Output

For eachcase, print one line containing the answer.

Sample Input

3

4 4 2

0 1

0 2

1 3

2 3

5 5 2

0 1

1 2

2 3

3 4

4 0

5 6 2

0 1

1 2

2 3

3 4

4 0

2 0

Sample Output

2

0

4

 

这题意思是有n个人,其中有m对朋友关系,其中不认识的两个人要成为朋友的条件是他们有至少k个共同的朋友,问最后能有多少对新朋友。
这题可以用图论解决,使用矩阵储存两个人之间的关系(1表示朋友关系,0表示不认识),然后遍历整个矩阵,寻找不认识的人的共同朋友,
并判断他们是否能成为新朋友,若能,则关系改为1,再重新遍历矩阵。


#include <iostream>
using namespace std;


int main()
{
int T;
cin>>T;
while(T--)
{
int n,m,k;
int P[105][105]={0};
cin>>n>>m>>k;
for(int i=1;i<=m;i++)
{
int u,v;
cin>>u>>v;
P[u][v]=1;
P[v][u]=1;
}   

int sum=0;
for(int i=0;i<n;i++)
   {
       for(int j=0;j<n;j++)
    {
    int cnt=0;
    if(i!=j&&P[i][j]==0)
    {
    for(int s=0;s<n;s++)
         if((P[i][s]==1)&&(P[j][s]==1))
        cnt++;
       if(cnt>=k)
   {
       sum++;
       P[i][j]=1;P[j][i]=1;
       i=-1;
       break;
   }
    }
    }
   }
     cout<<sum<<endl;
}
return 0;
}













评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值