XMU 1050 Diffuse Secret 【最短路】

来源:互联网 发布:软件代理商 编辑:程序博客网 时间:2024/06/07 09:13

1050: Diffuse Secret

Time Limit: 500 MS  Memory Limit: 64 MB
Submit: 10  Solved: 8
[Submit][Status][Web Board]

Description

  A secret is good in one, better in two, ill in three and worse in four. 
  ----Hi, I know a secret, come on I will tell you. But you must promise that you won’t tell it to other guys. 
  ----OK, of course I won't.
 
  Do you think they will keep the secret? No no, just like most people, they share their secrets with their own friends. If everybody knows a secret, it will never be secret any more. 
  For some reasons that know to all, TheBeet keep the salaries of employees as secret. But the employees don’t. At the beginning, everyone only knows how much he/she get. Everyday they share every secret they know with their friends (They don’t share the secret that they just heard today). For Example, A and B are good friends, B and C are good friends, A knows the secret a and secret d. B knows the secret b and secret c. C knows the secret e. After they share their secrets, A will know the secret abcd, B will know the secret abcde, C will know the secret bce. Today TheBeet increases every employee’s salary and he wonders when will be known to all employees.

Input

  The input file contains several test cases. 
  Each test case begins with two integers N, M 0 < N <= 100, 0 <= M <= (N * (N – 1)), N is the number of employee and M indicates there are M pairs of friend. 
  The following M lines contain 2 integers each line describing the pair of friends. 
N = 0 and M = 0 indicates the end of input and should not be processed.

Output

  For each test case, for each test case, output “Case #:” on the first line, '#' is the number of the test case. Then output a single integer as after such days, these secrets will never be secret. If there is one secret that some one will never know, you just output “Secret.” (Without quotes)

Sample Input

5 5
1 2
2 3
3 4
4 5
5 1
3 1
1 2
0 0

Sample Output

Case 1:
2
Case 2:
Secret.

HINT

Source

厦门大学第四届程序设计竞赛 第一次网络预赛 by TheBeet @ btALT

[Submit][Status][Web Board]


题目链接:

  http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1050

题目大意:

  每个人都有个秘密,他们每一天都会把自己的所有知道的秘密与他朋友分享

  当天得到的秘密不会分享。问所有人都知道所有秘密时是第几天。

题目思路:

  【最短路】

  考虑第i个人的秘密最迟到j,则秘密从i到j的传播为从i到j的最短路。

  那么所有人的秘密都到达最远的人的时间就为答案,即求所有人到所有人的最短路里的最大值。

  用floyd即可。




/****************************************************Author : CoolxxxCopyright 2017 by Coolxxx. All rights reserved.BLOG : http://blog.csdn.net/u010568270****************************************************/#include<bits/stdc++.h>#pragma comment(linker,"/STACK:1024000000,1024000000")#define abs(a) ((a)>0?(a):(-(a)))#define lowbit(a) (a&(-a))#define sqr(a) ((a)*(a))#define mem(a,b) memset(a,b,sizeof(a))const double EPS=1e-8;const int J=10000;const int MOD=100000007;const int MAX=0x7f7f7f7f;const double PI=3.14159265358979323;const int N=104;using namespace std;typedef long long LL;double anss;LL aans;int cas,cass;int n,m,lll,ans;int e[N][N],f[N][N];void floyd(){int i,j,k;for(k=1;k<=n;k++){for(i=1;i<=n;i++){if(i==k)continue;for(j=1;j<=n;j++){if(i==j || k==j)continue;f[i][j]=min(f[i][j],f[i][k]+f[k][j]);}}}}int main(){#ifndef ONLINE_JUDGEfreopen("1.txt","r",stdin);//freopen("2.txt","w",stdout);#endifint i,j,k,l;int x,y,z;//for(scanf("%d",&cass);cass;cass--)//for(scanf("%d",&cas),cass=1;cass<=cas;cass++)//while(~scanf("%s",s))while(~scanf("%d",&n)){scanf("%d",&m);if(!n && !m)break;ans=0;mem(f,0x01);printf("Case %d:\n",++cass);for(i=1;i<=m;i++){scanf("%d%d",&x,&y);f[x][y]=f[y][x]=e[x][y]=e[y][x]=1;}floyd();for(i=1;i<=n;i++){for(j=1;j<=n;j++){if(i==j)continue;ans=max(ans,f[i][j]);}}if(ans==0x01010101)puts("Secret.");else printf("%d\n",ans);}return 0;}/*////*/


0 0
原创粉丝点击