Link: Click to open the link
Today's new Floyd algorithm, can be used to find any two points of the shortest distance, with this problem practice practice. Reference code:
#include <stdio.h> #define INF 0x3f3f3f3f#define MAX 110int 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]+map[k][j]) map[i][j]=map[i][k]+map[k] [j];} int main () {while (scanf ("%d%d", &n,&m)!=eof) {for (Int. i=0;i<n;i++) for (int j=0;j<n;j++) if (i==j) map[i][j ]=0;elsemap[i][j]=inf;for (int i=0;i<m;i++) {int a,b;scanf ("%d%d", &a,&b); map[a][b]=map[b][a]=1;} Floyd (); int flag=0;for (int i=0;i<n;i++) {for (int j=0;j<i;j++) {if (map[i][j]>7) {flag=1;break;}} if (flag) break;} if (flag) printf ("no\n"); elseprintf ("yes\n");} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 18,696 degree separation (Floyd algorithm)