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 thank friends in common, they will become friends in several days. Currently, there are totallyn 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. ThenT cases follow. For each case, the first line contains three integers
n, m, k (1 ≤ n ≤ 100, 0 ≤ mn×(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 integersui, vi (0 ≤ui, vi
<n, ui ≠ vi) indicating there is friendship between personui and
vi.

Note: The edges in test data are generated randomly.

Output

For each case, 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

大概思路:

1,数学方法?

2,二进制求交集+搜索+减枝?

3,暴力枚举?

大部分人用的floyd思想递推 :

i认识x,j认识x,那么i就有可能和j是朋友 ,找到i认识j的路径(x数)多等于k即可,如果可以认识,我们动态建路即可









对floyd的理解

for(k=1;k<=n;k++)

for(i=1;i<=n;i++)

for(j=1;j<=n;j++)

if(...)...

其中k为最对循环次数,我们可以改成:

while(上一次有更新)

{

for(i=1;i<=n;i++)

for(j=1;j<=n;j++)

if(...)...+标记更新

}


#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<memory.h>
using namespace std;
bool map[101][101];
int n,m,k,ans;
void _update()
{
ans=0;
memset(map,false,sizeof(map));
}
void _in()
{
int x,y;
scanf("%d%d%d",&n,&m,&k);
for(int i=0;i<m;i++){
scanf("%d%d",&x,&y);
map[x][y]=map[y][x]=true;
}
}
void _solve()
{
bool temp=true;
while(temp)
{
temp=false;
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
{
if(map[i][j]) continue;
int cnt=0;
for(int f=0;f<n;f++)
if(map[i][f]&&map[j][f])
cnt++;
if(cnt>=k) {
ans++;
map[i][j]=map[j][i]=true;
temp=true;
}
}
}
printf("%d\n",ans);
}
int main()
{
int T;
scanf("%d",&T);
while(T--){
_update();
_in();
_solve();
}
}

zoj3710 friends(floyd变形)的更多相关文章

  1. UVA10048 Audiophobia[Floyd变形]

    UVA - 10048 Audiophobia Consider yourself lucky! Consider yourself lucky to be still breathing and h ...

  2. POJ2253——Frogger(Floyd变形)

    Frogger DescriptionFreddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fi ...

  3. hdu 1596(Floyd 变形)

    http://acm.hdu.edu.cn/showproblem.php?pid=1596 find the safest road Time Limit: 10000/5000 MS (Java/ ...

  4. hdu 1217 (Floyd变形)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217 Arbitrage Time Limit: 2000/1000 MS (Java/Others)   ...

  5. Frogger(floyd变形)

    Frogger Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Stat ...

  6. UVa 10048 (Floyd变形) Audiophobia

    题意: 给一个带权无向图,和一些询问,每次询问两个点之间最大权的最小路径. 分析: 紫书上的题解是错误的,应该是把原算法中的加号变成max即可.但推理过程还是类似的,如果理解了Floyd算法的话,这个 ...

  7. find the mincost route(floyd变形 无向图最小环)

    Time Limit: 1000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  8. hdu1569find the safest road(floyd变形求最大安全值)

    find the safest road Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  9. HDU 4034 Graph(Floyd变形——逆向判断)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4034 Problem Description Everyone knows how to calcu ...

随机推荐

  1. JVM启动参数设置

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt174 不管是YGC还是Full GC,GC过程中都会对导致程序运行中中断,正 ...

  2. FTP的主动和被动模式详解

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp25 主动模式FTP与被动模式FTP该如何选择 一.主动模式的实现与特点. ...

  3. Python 多线程库总结

    多线程库总结 基于线程的并行性 threading模块 下面是一些基础函数,函数包括: 函数 threading.active_count() threading.current_thread() t ...

  4. C++学习笔记——STL(标准模板库)

    1.首先.需要学习C++ 模板的概念 2.C++ STL(标准模板库)是一套功能强大的 C++ 模板类,提供了通用的模板类和函数,这些模板类和函数可以实现多种流行和常用的算法和数据结构,如向量.链表. ...

  5. 201521123003《Java程序设计》第6周学习总结

    1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图,对面向对象思想进行一个总结. 注1:关键词与内容不求多,但概念之间的联系要清晰,内容覆盖 ...

  6. 201521123077 《Java程序设计》第9周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常相关内容. 异常分为uncheckedException和checkedException checkedException 继 ...

  7. Java第十三周学习总结

    1. 本周学习总结 以你喜欢的方式(思维导图.OneNote或其他)归纳总结多网络相关内容. 2. 书面作业 1. 网络基础 1.1 比较ping www.baidu.com与ping cec.jmu ...

  8. Spring写第一个应用程序

    ref:http://www.importnew.com/13246.html 让我们用Spring来写第一个应用程序吧. 完成这一章要求: 熟悉Java语言 设置好Spring的环境 熟悉简单的Ec ...

  9. Flask-WTF 入门使用P1

    创建表单 Flask-WTF为您的Flask应用程序集成了WTForms,具体例子如下: from flask_wtf import FlaskForm from wtforms import Str ...

  10. MySQL线程池的引入可以提高我们的MySQL的性能

    支持线程池的版本:MySQL 企业版本,MySQL percona的分支 MariDB 的版本.我们知道我们的MySQL 语句是不支持硬解析的,没有无SQL 解析 cache.每个连接对应一个线程,我 ...