63512023-11-23 19:07:17MrChipserRácsháló gráfcpp11Time limit exceeded 47/50600ms4588 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];
            }
        }
    }
    }
    //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/0600ms1448 KiB
3Accepted2/24ms2440 KiB
4Accepted2/23ms2588 KiB
5Accepted2/23ms2644 KiB
6Accepted2/24ms2768 KiB
7Accepted2/235ms3168 KiB
8Accepted2/235ms3380 KiB
9Accepted2/235ms3336 KiB
10Accepted2/213ms3300 KiB
11Accepted2/237ms3596 KiB
12Accepted2/2340ms3876 KiB
13Accepted3/3465ms3928 KiB
14Accepted3/346ms4024 KiB
15Accepted3/3446ms4004 KiB
16Accepted3/337ms3832 KiB
17Accepted3/3333ms3856 KiB
18Accepted3/379ms3976 KiB
19Accepted3/34ms4180 KiB
20Accepted3/37ms4372 KiB
21Accepted3/3104ms4492 KiB
22Time limit exceeded0/3574ms4588 KiB