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. iOS.OpenSource.PopularProject

    1. Core Plot Core Plot is a plotting framework for OS X and iOS. It provides 2D visualization of dat ...

  2. Games.RecordMobileGamePlayVideo

    1. kamcord https://github.com/kamcord/ 2. Sound Stage & iSimulate http://blog.tacograveyard.com/ ...

  3. 厉害了,PS大神真的能改变世界!

    今天要介绍的这位PS大神 名叫 Katrina Yu 她的操作真的神了 不管多普通的场景 她都能帮你改头换面 在后院破旧的椅子上喝着咖啡 一转眼就骑着魔法扫帚 飞上了天,与月亮肩并肩 看原图还以为是在 ...

  4. php实现MySQL两库对比升级版

    define('DATABASE1', 'db1'); $dbi1 = new DbMysql; $dbi1->dbh = 'mysql://root:password@127.0.0.1/'. ...

  5. Bootstrap学习遇到的role属性--- 无障碍网页应用属性

    以前接触过Bootstrap,但也只是仅仅接触,现在重新学习下,今天看到一个例子中的属性有一个role, 查阅资料发现这个是--WAI-ARIA无障碍设计属性: 通俗说是该设计为了一些盲人,失聪,残疾 ...

  6. springMVC学习 七 视图解析器

    在springMVC中,如果不配置视图解析器,会走默认的视图解析器,但是有时候配置视图解析器,还有一定的作用 <bean id="viewResolver" class=&q ...

  7. canvas 实现赛车游戏

    一:创建画布 <canvas width="200" height="500" id="canvas" style="bor ...

  8. 再读c++primer plus 006

    使用类: 1.重载限制:(1)重载后的运算符必须至少有一个操作数是用户定义的类型,这将防止用户为标准类型重载运算符 (2)使用运算符时不能违反运算符原来的语法规则,不能修改运算符的优先级 (3)不能创 ...

  9. kbmmw 中JSON 操作入门

    现在各种系统中JSON 用的越来越多.delphi 也自身支持JSON 处理. 今天简要说一下kbmmw 内部如何使用和操作JSON. kbmmw 中json的操作是以TkbmMWJSONStream ...

  10. mysql 批量杀进程

    select concat('KILL ',id,';') from information_schema.processlist where user='root';