63532023-11-23 19:10:26MrChipserRácsháló gráfcpp11Wrong answer 27/50140ms4888 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 < 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
base27/50
1Accepted0/03ms1820 KiB
2Wrong answer0/0115ms2456 KiB
3Accepted2/23ms2280 KiB
4Accepted2/23ms2364 KiB
5Wrong answer0/23ms2372 KiB
6Wrong answer0/23ms2360 KiB
7Accepted2/26ms2676 KiB
8Wrong answer0/24ms2628 KiB
9Wrong answer0/24ms2892 KiB
10Wrong answer0/24ms3140 KiB
11Wrong answer0/28ms3420 KiB
12Wrong answer0/26ms3676 KiB
13Accepted3/3140ms3392 KiB
14Accepted3/37ms3480 KiB
15Accepted3/341ms3732 KiB
16Wrong answer0/34ms3912 KiB
17Accepted3/319ms3960 KiB
18Accepted3/38ms4168 KiB
19Wrong answer0/33ms4024 KiB
20Accepted3/33ms4392 KiB
21Accepted3/312ms4720 KiB
22Wrong answer0/357ms4888 KiB