博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Friends (ZOJ - 3710)
阅读量:4619 次
发布时间:2019-06-09

本文共 1772 字,大约阅读时间需要 5 分钟。

Problem

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 ithfriendship contains two integers ui, vi (0 ≤ ui, vi < n, ui ≠ 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

题解:暴力遍历所有朋友直到不再出现新的朋友关系就可以了。

#include 
#include
#include
#include
#include
#include
using namespace std;typedef long long ll;int vis[110][110]; //用来判断是否是朋友关系int main(){ int n,i,j,m,t,k,ans,x,y,l; while(scanf("%d",&t) != EOF) { while(t--) { scanf("%d%d%d",&n,&m,&k); memset(vis,0,sizeof(vis)); for(i=0; i
=k) { ans++; vis[i][j] = vis[j][i] = 1; } } } if(m==ans) break; // 如果和上次循环的结果一样,就说明不会再增加新的朋友关系了,跳出循环就可以了 m = ans; } printf("%d\n",ans); } } return 0;}

 

转载于:https://www.cnblogs.com/lcchy/p/10139628.html

你可能感兴趣的文章
angular repeat
查看>>
android 图片圆角化控件
查看>>
java第三次作业
查看>>
HP Jack介绍
查看>>
敏捷软件开发(3)---COMMAND 模式 & Active Object 模式
查看>>
poj 1062 昂贵的聘礼 解题报告
查看>>
get the page name from url
查看>>
visual studio中csproj文件中的project guid改为小写 ( notepad++ 正则)
查看>>
TeeChart显示三维的图形,使用Surface
查看>>
如何使用 Idea 远程调试 Java 代码
查看>>
加密,解密
查看>>
在C#代码中应用Log4Net(一)简单使用Log4Net
查看>>
[转]如何写软件项目技术标
查看>>
每日站立会议个人博客五
查看>>
ddd
查看>>
死磕 java同步系列之AQS起篇
查看>>
利用Lucene把文本的字体格式进行改动,然后输出到一个新的文件里
查看>>
[Openstack] Expecting an auth URL via either --os-auth-url or env[OS_AUTH_URL]
查看>>
How to Create Modifiers Using the API QP_MODIFIERS_PUB.PROCESS_MODIFIERS
查看>>
待飞笔记(第一天 )
查看>>