63542023-11-23 19:11:36MrChipserRácsháló gráfcpp11Time limit exceeded 39/50570ms4772 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/2; 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
base39/50
1Accepted0/03ms1828 KiB
2Time limit exceeded0/0570ms2284 KiB
3Accepted2/23ms2516 KiB
4Accepted2/23ms2680 KiB
5Accepted2/23ms2792 KiB
6Wrong answer0/23ms2988 KiB
7Accepted2/217ms3388 KiB
8Accepted2/217ms3596 KiB
9Accepted2/217ms3808 KiB
10Wrong answer0/27ms3860 KiB
11Wrong answer0/217ms3868 KiB
12Wrong answer0/2158ms4132 KiB
13Accepted3/3211ms4320 KiB
14Accepted3/321ms4416 KiB
15Accepted3/3201ms4520 KiB
16Accepted3/318ms4612 KiB
17Accepted3/3152ms4668 KiB
18Accepted3/337ms4628 KiB
19Accepted3/33ms4516 KiB
20Accepted3/34ms4524 KiB
21Accepted3/348ms4560 KiB
22Time limit exceeded0/3564ms4772 KiB