蒜厂年会(floyd)

蒜厂年会

#include <bits/stdc++.h>

using namespace std;

const int MAXN = 305;
const int INF = 0x3f3f3f3f;
int group1[MAXN];
int group2[MAXN];
int G[MAXN][MAXN];
int n, m;

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

void print()
{
    for(int i = 1; i <= n; ++i)
    {
        for(int j = 1; j <= n; ++j)
        {
            if( (i != j) )
            {
                cout << G[i][j] << " ";
            }
        }
        cout << endl;
    }
}

int main()
{
    //freopen("data.in","r",stdin);
    //freopen("data.out","w",stdout);
    ios::sync_with_stdio(false);

    memset(G, INF, sizeof(G));

    cin >> n >> m;
    for(int i = 0; i < m ; ++i)
    {
        int len ;
        cin >> len;
        for(int j = 0; j < len; ++j)
        {
            cin >> group1[j];
            group2[j] = group1[j];
        }

        for(int x = 0; x < len; ++x)
        {
            for(int y = 0; y < len; ++y)
            {
                if(x != y)
                {
                    G[group1[x]][group2[y]] = 1;
                }
            }
        }
    }

    floyd();
    //print();

    double MINV = INF;
    for (int i= 1; i<= n; i++)
    {
        double sumn = 0;
        for (int j = 1; j<= n; j++)
        {
            if(i!=j)
                sumn += G[i][j];
        }

        MINV = min(sumn/(n-1), MINV);
    }

    cout << (int)(MINV * 100);

    return 0;
}

猜你喜欢

转载自blog.csdn.net/ccshijtgc/article/details/83176000