zoukankan      html  css  js  c++  java
  • 1869六度分离

    实在是太粗心了,floyd算法中把k打成了i,找了20分钟才找到错.... 题目不难,最多用6个人就能联系在一起,等价于任意2点的距离不超过7

    #include <iostream>
    #include <algorithm>
    #include <cstring>
    using namespace std;
    
    #ifndef ONLINE_JUDGE
    #include <fstream>
    ifstream fin("test.txt");
    #define cin fin
    #endif
    int graph[110][110],n,m;
    const int INF = 1000000;
    void floyd()
    {
    
        int i,j,k;
        for(k = 0; k < n; ++k)
        for(i = 0; i < n; ++i)
        for(j = 0; j < n; ++j)
        graph[i][j] = min(graph[i][j],graph[i][k]+graph[k][j]);    
    }
    bool judge()
    {
        for(int i = 0; i < n; ++i)
        for(int j = i + 1; j < n; ++j)
        if(graph[i][j] > 7)
        return 0;
        return 1;
    }
    int main()
    {
        ios::sync_with_stdio(false);
        int a,b;
        while(cin >> n >> m)
        {
            for(int i = 0; i < n; ++i)
            for(int j = 0; j < n; ++j)
            if(i == j)
            graph[i][j] = 0;
            else
            graph[i][j] = INF;
            while(m--)
            {
                cin >> a >> b;
                graph[a][b] = graph[b][a] = 1;
            }
            floyd();
            if(judge())
            cout << "Yes" << endl;
            else
            cout << "No" << endl;
        }
        return 0;
    }
  • 相关阅读:
    20140710 sequence 前缀和
    20140709 testC 数学题
    20140708 testA 组合数学
    20140708 testB DP 组合数学
    Sad :(
    已经是一个废人了……
    Game Theory
    HDU Math Problems
    2-sat问题
    并查集
  • 原文地址:https://www.cnblogs.com/fchx/p/3097584.html
Copyright © 2011-2022 走看看