hdu 1869 floyd

认识的人之间建立一条权值为1的边,然后求出各对顶点之间的最短路判断是否有长度大于7的。

 1 #include <algorithm>
 2 #include <iostream>
 3 #include <cstring>
 4 #include <cstdio>
 5 using namespace std;
 6
 7 const int INF = 999999;
 8 const int N = 100;
 9 int g[N][N];
10 int n, m;
11
12 void init()
13 {
14     for ( int i = 0; i < n; i++ )
15     {
16         for ( int j = 0; j < n; j++ )
17         {
18             g[i][j] = INF;
19         }
20     }
21 }
22
23 void floyd()
24 {
25     for ( int k = 0; k < n; k++ )
26     {
27         for ( int i = 0; i < n; i++ )
28         {
29             for ( int j = 0; j < n; j++ )
30             {
31                 if ( g[i][k] + g[k][j] < g[i][j] )
32                 {
33                     g[i][j] = g[i][k] + g[k][j];
34                 }
35             }
36         }
37     }
38 }
39
40 void judge()
41 {
42     for ( int i = 0; i < n; i++ )
43     {
44         for ( int j = 0; j < n; j++ )
45         {
46             if ( i == j ) continue;
47             if ( g[i][j] > 7 )
48             {
49                 printf("No\n");
50                 return ;
51             }
52         }
53     }
54     printf("Yes\n");
55 }
56
57 int main ()
58 {
59     while ( scanf("%d%d", &n, &m) != EOF )
60     {
61         init();
62         while ( m-- )
63         {
64             int a, b;
65             scanf("%d%d", &a, &b);
66             g[a][b] = g[b][a] = 1;
67         }
68         floyd();
69         judge();
70     }
71     return 0;
72 }
时间: 2024-08-01 11:08:04

hdu 1869 floyd的相关文章

hdu 1869 (Floyd)

http://acm.hdu.edu.cn/showproblem.php?pid=1869 六度分离 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4355    Accepted Submission(s): 1768 Problem Description 1967年,美国著名的社会学家斯坦利·米尔格兰姆提出了一个名为“小世界现象

ACM: HDU 1869 六度分离-Dijkstra算法

HDU 1869六度分离 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description 1967年,美国著名的社会学家斯坦利·米尔格兰姆提出了一个名为“小世界现象(small world phenomenon)”的著名假说,大意是说,任何2个素不相识的人中间最多只隔着6个人,即只用6个人就可以将他们联系在一起,因此他的理论也被称为“六度分离”理论(six degrees of se

hdu 1599 floyd 最小环

floyd真的是水很深啊 各种神奇 #include<stdio.h> #include<string.h> #include<math.h> #include<iostream> #include<algorithm> #include<queue> #include<stack> #define mem(a,b) memset(a,b,sizeof(a)) #define ll __int64 #define MAXN

HDU 1847(floyd)

畅通工程续 高仿代码如下 #include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int inf = 0x3f3f3f3f;#define N 205int d[N][N];void floyd(int n){    for(int k = 0;k < n;k++)    for(int i = 0;i <

hdu 1869 六度分离(最短路floyd)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1869 六度分离 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5171    Accepted Submission(s): 2089 Problem Description 1967年,美国著名的社会学家斯坦利·米尔格兰姆提出了一个名为“

HDU 1869 六度分离(最短路 floyd)

六度分离 Problem Description 1967年,美国著名的社会学家斯坦利·米尔格兰姆提出了一个名为“小世界现象(small world phenomenon)”的著名假说,大意是说,任何2个素不相识的人中间最多只隔着6个人,即只用6个人就可以将他们联系在一起,因此他的理论也被称为“六度分离”理论(six degrees of separation).虽然米尔格兰姆的理论屡屡应验,一直也有很多社会学家对其兴趣浓厚,但是在30多年的时间里,它从来就没有得到过严谨的证明,只是一种带有传奇

hdu 1869 六度分离(Floyd算法)

本题链接:点击打开链接 今天新学的Floyd算法,可用来求任意两点的最短距离,用此题练习练习.参考代码: #include<stdio.h> #define INF 0x3f3f3f3f #define MAX 110 int map[MAX][MAX]; int n,m; void Floyd() { for(int k=0;k<n;k++) for(int i=0;i<n;i++) for(int j=0;j<n;j++) if(map[i][j]>map[i][k

HDU 1869 六度分离(floyd)

#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<iostream> #define INF 1000000 using namespace std; int d[200][200]; int main() { int n,m; while(scanf("%d%d",&n,&m)!=EOF) { int

hdu 六度分离 floyd

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1869 题意分析:比较简单的最短路算法,最后只需判断最远两点距离是否大于7即可. /*六度分离 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4992 Accepted Submission(s): 2010 Problem Descriptio