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. python re正则

    一:什么是正则? 正则就是用一些具有特殊含义的符号组合到一起(称为正则表达式)来描述字符或者字符串的方法.或者说:正则就是用来描述一类事物的规则.(在Python中)它内嵌在Python中,并通过 r ...

  2. NSIS Error:Error writing temporary file. Make sure your temp folder is valid的解决办法

    我的是Win7 32位,当前登录用户已经是管理员,在安装腾讯视频电脑版时,提示以上错误,无法安装. 查了好多资料,按如下方法解决了: 在win7下,以管理员的身份打开cmd(在window\syste ...

  3. phpstorm+xdebug调试代码

    1工具 #phpstorm 前面有文章介绍如何安装 #phpStudy 官网下的2018最新的安装包,php环境使用的也是最新的php7.0nts 2开启php Xdebug拓展 开启拓展,phpSt ...

  4. iOS.Info.plist

    1. Custom message when asking for Address Book Permissions http://kevinyavno.com/blog/?p=176

  5. javascript 高级程序设计 一

    前言: 作为一个即将毕业.正在实习的大学生,我也默默的进入了开发者的行列.从一开始的c#编码狗到java程序员再到现在的JS开发者,我一直 希望自己可以在这个'万恶'的互联网时代走的更远.但是我还是一 ...

  6. [转载]linux awk命令详解

    简介 awk是一个强大的文本分析工具,相对于grep的查找,sed的编辑,awk在其对数据分析并生成报告时,显得尤为强大.简单来说awk就是把文件逐行的读入,以空格为默认分隔符将每行切片,切开的部分再 ...

  7. TP 真阳性 TN FP FN

    TP.True Positive   真阳性:预测为正,实际也为正 FP.False Positive  假阳性:预测为正,实际为负 FN.False Negative 假阴性:预测与负.实际为正 T ...

  8. 如何查看api项目接口

    http://www.api.com/Api/Page/index/?format_type=json&api_cate=cms&ma=8026

  9. 更精确的判断对象类型js方法

    function isArray(o) { return Object.prototype.toString.call(o) === '[object Array]'; } function isRe ...

  10. openssl RSA加密方法初识

    作为非对称加密算法,有两对密钥 一般用法 加密结果=RSA_EN(数据,公钥); 解密结果=RSA_DE(数据,私钥); RSA填充 (RSA_public_encrypt和RSA_private_d ...