63522023-11-23 19:09:24MrChipserRácsháló gráfcpp11Time limit exceeded 47/50600ms4136 KiB
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
int n,m,k;
int csm[200][200];

int bfs()
{
    int mtav = 0;
    for(int j = 0; j < n*m; j++)
    {
    int votma[n*m]={0};
    int tav[n*m] = {0};
    queue<int>q;
    q.push(j);
    votma[j]=1;
    while(!q.empty())
    {
        int akt = q.front();
        //cout << akt << " ";
        q.pop();
        for(int i = 0; i <n*m; i++)
        {
            if(csm[akt][i]==1 && votma[i]==0)
            {
                q.push(i);
                votma[i]=1;
                tav[i]=tav[akt]+1;
                //cout << tav[i] << " " << tav[akt] << " " << i  << " " << akt<< endl;
                if(tav[i]>mtav)
                    mtav=tav[i];
            }
        }
    }
    if(mtav==(n-1)+(m-1))
        break;
    }
    //for(int i = 0; i < n*m; i++)
     //   cout << tav[i] << " ";
    //cout << endl;
    return mtav;
}

int main()
{
    cin >> n >> m >> k;
    for(int i = 0; i < n*m; i++)
        for(int j = 0; j < n*m; j++)
            csm[i][j]=0;
    for(int i = 0; i < n*m; i++)
    {
        if(i < n*m-m)
        {
            csm[i][i+m]=1;
            csm[i+m][i]=1;
        }
        if((i+1)%m!=0)
        {
            //cout << i << endl;
            csm[i][i+1]=1;
            csm[i+1][i]=1;
        }
    }
   // for(int i = 0; i < n*m; i++)
   // {
        //for(int j = 0; j < n*m; j++)
            //cout << csm[i][j];
        //cout << endl;
  //  }
    vector<int>maxut;
    for(int i = 0; i < k; i++)
    {
        int x,y;
        cin >> x >> y;
        csm[x-1][y-1]=1;
        csm[y-1][x-1]=1;
        maxut.push_back(bfs());

    }
    for(int i = 0; i < maxut.size(); i++)
        cout << maxut[i] << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base47/50
1Accepted0/03ms1824 KiB
2Time limit exceeded0/0600ms1420 KiB
3Accepted2/23ms2272 KiB
4Accepted2/23ms2488 KiB
5Accepted2/23ms2572 KiB
6Accepted2/24ms2664 KiB
7Accepted2/235ms2944 KiB
8Accepted2/235ms2984 KiB
9Accepted2/235ms3240 KiB
10Accepted2/212ms3420 KiB
11Accepted2/235ms3404 KiB
12Accepted2/2337ms3892 KiB
13Accepted3/3453ms3616 KiB
14Accepted3/345ms3448 KiB
15Accepted3/3430ms3780 KiB
16Accepted3/337ms3700 KiB
17Accepted3/3324ms3744 KiB
18Accepted3/375ms3928 KiB
19Accepted3/34ms3936 KiB
20Accepted3/36ms4016 KiB
21Accepted3/3100ms3952 KiB
22Time limit exceeded0/3550ms4136 KiB