Six Degrees of Cowvin Bacon
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 3602 |
|
Accepted: 1675 |
Description
the cows has been making movies lately, so they is ready to play a variant of the famous game "Six Degrees of Kevin Bacon ".
The game works like This:each Cow are considered to being zero degrees of separation (degrees) away from herself. If the distinct cows has been in a movie together, and each was considered to being one ' degree ' away from the other. If A, cows has never worked together but has both worked with a third cow, they is considered to be ' degrees ' AW Ay from each of the other (counted As:one degree to the cow they ' ve worked with and one more to the other cow). This is scales to the general case.
The N (2 <= n <=) cows is interested in figuring out which cow have the smallest average degree of separatio N from all and the other cows. Excluding herself of course. The cows has 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 in or more space-separated integers that describes the cows Appeari Ng 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 This is the shortest mean degree of separation of any of the cows.
Sample Input
4 23 1 2 32 3 4
Sample Output
100
Hint
[Cow 3 have worked with all the other cows and thus have degrees of separation:1, 1, and 1--a mean of 1.00.]
Source
Usaco 2003 March OrangeWell, the problem is that I don't understand it, and finally Google has a problem with someone else's solution. question: In homage to a theory that "anyone can access up to 5 people to recognize anyone," a group of cows decided to shoot the movie,there are n cows, a M movie, and you have a role in every movie. if 2 cows appear in the same movie, they are aware that the distance is 1, if 2 cows do not appear in the same film, but they are aware of the 3rd cow, their distance is 2, a type of push. ". Requirements:find a cow, his distance to all the other cows and sum is the smallest, the smallest average distance, namely sum/(N-1),Rounding down. Floyd just fine.
1#include <cstdio>2#include <cstring>3#include <algorithm>4 5 using namespacestd;6 7 Const intinf=0x3f3f3f3f;8 Const intmaxn=303;9 Ten intDP[MAXN][MAXN]; One intTMP[MAXN]; A - voidInitintN) - { the for(intI=1; i<=n;i++) - { - for(intj=1; j<=n;j++) - { + if(i==j) -dp[i][j]=0; + Else Adp[i][j]=INF; at } - } - } - - voidFloydintN) - { in for(intk=1; k<=n;k++) - for(intI=1; i<=n;i++) to for(intj=1; j<=n;j++) +Dp[i][j]=min (dp[i][j],dp[i][k]+dp[k][j]); - } the * voidSolveintN) $ {Panax Notoginseng intMinc=INF; - for(intI=1; i<=n;i++) the { + intsum=0; A for(intj=1; j<=n;j++) thesum+=Dp[i][j]; + if(sum<minc) -Minc=sum; $ } $printf"%d\n", minc* -/(n1)); - } - the intMain () - {Wuyi intn,m; the while(~SCANF ("%d%d",&n,&M)) - { Wu init (N); - for(intI=0; i<m;i++) About { $ intu; -scanf"%d",&u); - for(intj=1; j<=u;j++) -scanf"%d",&tmp[j]); A for(intj=1; j<=u;j++) + { the for(intk=1; k<=u;k++) - { $ if(j==k) the Continue; thedp[tmp[j]][tmp[k]]=1; the } the } - } in Floyd (N); the the solve (N); About } the return 0; the}
View Code
POJ 2139 SIx Degrees of Cowvin Bacon the shortest-circuited water problem