The cows have been making movies lately, so they are ready to play a variant of the famous game "Six Degrees of Kevin Bacon".

The game works like this: each cow is considered to be zero degrees of separation (degrees) away from herself. If two distinct cows have been in a movie together, each is considered to be one 'degree' away from the other. If a two cows have never worked together but have both worked with a third cow, they are considered to be two 'degrees' away from each other (counted as: one degree to the cow they've worked with and one more to the other cow). This scales to the general case.

The N (2 <= N <= 300) cows are interested in figuring out which cow has the smallest average degree of separation from all the other cows. excluding herself of course. The cows have made M (1 <= M <= 10000) movies and it is guaranteed that some relationship path exists between every pair of cows.

Input

* Line 1: Two space-separated integers: N and M

* Lines 2..M+1: Each input line contains a set of two or more space-separated integers that describes the cows appearing in a single movie. The first integer is the number of cows participating in the described movie, (e.g., Mi); the subsequent Mi integers tell which cows were.

Output

* Line 1: A single integer that is 100 times the shortest mean degree of separation of any of the cows. 

Sample Input

4 2
3 1 2 3
2 3 4

Sample Output

100

Hint

[Cow 3 has worked with all the other cows and thus has degrees of separation: 1, 1, and 1 -- a mean of 1.00 .] 
 
 
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std; int way[][]; int main(){
int n,m;
cin>>n>>m;
int temp[];
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
way[i][j]=INT_MAX;
if(j==i)
way[i][i]=;
}
}
for(int i=;i<m;i++){
int num;
cin>>num;
for(int j=;j<num;j++){
cin>>temp[j];
} for(int j=;j<num;j++){
for(int w=j+;w<num;w++){
way[temp[j]][temp[w]]=way[temp[w]][temp[j]]=;
}
}
} for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
for(int w=;w<=n;w++){
if(way[j][i]!=INT_MAX&&way[i][w]!=INT_MAX)
way[j][w]=min(way[j][w],way[j][i]+way[i][w]);
}
}
}
int ans=INT_MAX;
for(int i=;i<=n;i++){
int t=;
for(int j=;j<=n;j++){
t+=way[i][j];
}
ans=min(ans,t);
}
cout<<ans*/(n-);
return ;
}

POJ2139--Six Degrees of Cowvin Bacon(最简单Floyd)的更多相关文章

  1. POJ2139 Six Degrees of Cowvin Bacon [Floyd]

    水题,随手敲过 一看就是最短路问题,a,b演同一场电影则他们的距离为1 默认全部两两原始距离无穷,到自身为0 输入全部数据处理后floyd 然后照它说的求平均分离度 再找最小的,×100取整输出 #i ...

  2. 【Floyd】POJ2139 -Six Degrees of Cowvin Bacon

    普通的Floyd了分分秒可以水过,结果在submit前删调试段落的时候把程序本体给删了吃了两个WA…… #include<iostream> #include<cstring> ...

  3. poj2139 Six Degrees of Cowvin Bacon

    思路: floyd 实现: #include <iostream> #include <cstdio> #include <cstring> #include &l ...

  4. AOJ -0189 Convenient Location && poj 2139 Six Degrees of Cowvin Bacon (floyed求任意两点间的最短路)

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=78207 看懂题就好. 求某一办公室到其他办公室的最短距离. 多组输入,n表示 ...

  5. 【POJ - 2139】Six Degrees of Cowvin Bacon (Floyd算法求最短路)

    Six Degrees of Cowvin Bacon Descriptions 数学课上,WNJXYK忽然发现人缘也是可以被量化的,我们用一个人到其他所有人的平均距离来量化计算. 在这里定义人与人的 ...

  6. POJ 2139 Six Degrees of Cowvin Bacon (floyd)

    Six Degrees of Cowvin Bacon Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Ja ...

  7. POJ:2139-Six Degrees of Cowvin Bacon

    传送门:http://poj.org/problem?id=2139 Six Degrees of Cowvin Bacon Time Limit: 1000MS Memory Limit: 6553 ...

  8. <poj - 2139> Six Degrees of Cowvin Bacon 最短路径问题 the cow have been making movies

    本题链接:http://poj.org/problem?id=2139 Description:     The cows have been making movies lately, so the ...

  9. ShortestPath:Six Degrees of Cowvin Bacon(POJ 2139)

    牛与电影 题目大意:就是一群牛,又在玩游戏了(怎么你们经常玩游戏),这个游戏规则如下,把牛拆分成一个一个组,并且定义一个“度”,规定在一个组的牛与他自己的度为0,与其他牛的度为1,不同组的牛不存在度, ...

随机推荐

  1. hdu 1757 (矩阵快速幂) 一个简单的问题 一个简单的开始

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1757 题意不难理解,当x小于10的时候,数列f(x)=x,当x大于等于10的时候f(x) = a0 * ...

  2. String类为什么设计成不可变的

    在Java中将String设计成不可变的是综合考虑到各种因素的结果,需要综合考虑内存.同步.数据结构以安全方面的考虑. String被设计成不可变的主要目的是为了安全和高效. 1)字符串常量池的需要 ...

  3. [Python] 代码中有中文注释会报错

    原因 如果文件里有非ASCII字符,需要在第一行或第二行指定编码声明. 解决方法 在第一行或是第二行加入这么一句# -- coding: utf-8 -- ASCII知识普及: ASCII(Ameri ...

  4. 学习C语言以及C语言基础调查

    学习声乐的心得 你有什么技能比大多人(超过90%以上)更好?   就我个人而言,在所有的兴趣之中,做得比较好的应该属于声乐. 针对这个技能的获取你有什么成功的经验?   我对于声乐处始于兴趣,成功的经 ...

  5. netty1 快速入门

    Netty是一个高性能.异步事件驱动的网路通信框架 ,由于精力有限,本人并没有对其源 码做了特别细致的研究.如果下面的内容有错误或不严谨的地方,也请大家指正和谅解. Netty的线程模型是Reacto ...

  6. ContactDetail 和 ContactEditor 界面头像响应点击过程

    1,联系人详情界面 ContactDetailFragment中处理,ViewAdapter装载数据显示头像 private final class ViewAdapter extends BaseA ...

  7. 蛋白序列GO号注释及问题

    #===============================      版本1  ===============================================InterProSc ...

  8. 【转载】 IP实时传输协议RTP/RTCP详解

    http://www.chinaitlab.com/cisco/RIP/832426.html 1.简介 目前,在IP网络中实现实时语音.视频通信和应用已经成为网络应用的一个主流技术和发展方向,本文详 ...

  9. python学习 day20 (3月27日)----(单继承多继承c3算法)

    继承: 提高代码的重用性,减少了代码的冗余 这两个写法是一样的 Wa('青蛙').walk() #青蛙 can walk wa = Wa('青蛙') wa.walk() #青蛙 can walk 1. ...

  10. 819. Most Common Word

    static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...