201503-4 网络延时 floyd骗70分

#include <iostream>
#include <deque>
#include <cstdio>
#include <sstream>
#include <string>
using namespace std;
const int maxn = 200;
const int INF = 0x3fffffff;
int Mgraph[maxn][maxn];
int n,m;
void flord()
{
    
    
    for(int k=1;k<=n+m;k++)
    {
    
    
        for(int i=1;i<=n+m;i++)
        {
    
    
            for(int j=1;j<=n+m;j++)
            {
    
    
                if(Mgraph[i][k]!=INF&&Mgraph[k][j]!=INF&&Mgraph[i][j] > Mgraph[i][k]+Mgraph[k][j])
                    Mgraph[i][j] = Mgraph[i][k]+Mgraph[k][j];
            }
        }
    }
}
int main()
{
    
    
    fill(Mgraph[0],Mgraph[0]+maxn*maxn,INF);
    int i,excom,max_ans = 0;
    cin>>n>>m;
    for(i=1;i<=n+m;i++)
        Mgraph[i][i] = 0;
    for(i=2;i<=n+m;i++)
    {
    
    
        cin>>excom;
        Mgraph[excom][i] = 1;
        Mgraph[i][excom] = 1;
    }
    flord();
    for(int i=1;i<=n+m;i++)
    {
    
    
        for(int j=1;j<=n+m;j++)
        {
    
    
            if(max_ans < Mgraph[i][j])
                max_ans = Mgraph[i][j];
        }
    }
    cout<<max_ans;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_44142774/article/details/113851685
今日推荐