JSK-美好的邂逅-最短路Floyd

题目在这

Floyd 的水题
AC代码

#include

using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 105;
const int maxm = 205;

int amap[maxn][maxn];
int m, n;

void floyd()
{
    for(int k = 1; k <= n; k++){
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                if(amap[i][j] > amap[i][k] + amap[k][j])
                    amap[i][j] = amap[i][k] + amap[k][j];
            }
        }
    }
}

int main()
{
    cin>>n>>m;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++){
            amap[i][j] = inf;
            if(i == j)
                amap[i][j] = 0;
        }


    for(int i = 0; i < m; i++){
        int a,b;
        cin>>a>>b;
        amap[a][b] = 1;
        amap[b][a] = 1;
    }
    floyd();
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= i; j++){
            if(amap[i][j] - 1 > 6){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

你可能感兴趣的:(acm,最短路,Floyd)