63562023-11-23 19:21:53MrChipserRácsháló gráfcpp11Accepted 50/5054ms4824 KiB
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
int n,m,k;
int csm[200][200];
vector<int> adj[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(auto x : adj[akt])
        {
            if(votma[x]==0)
            {
                q.push(x);
                votma[x]=1;
                tav[x]=tav[akt]+1;
                //cout << tav[i] << " " << tav[akt] << " " << i  << " " << akt<< endl;
                if(tav[x]>mtav)
                    mtav=tav[x];
            }
        }
    }
    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++)
        {
            if(csm[i][j]==1)
            {
                adj[i].push_back(j);
            }
        }
    //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;
        adj[x-1].push_back(y-1);
        adj[y-1].push_back(x-1);
        maxut.push_back(bfs());

    }
    for(int i = 0; i < maxut.size(); i++)
        cout << maxut[i] << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1976 KiB
2Accepted0/052ms2536 KiB
3Accepted2/23ms2252 KiB
4Accepted2/23ms2464 KiB
5Accepted2/23ms2676 KiB
6Accepted2/23ms2888 KiB
7Accepted2/24ms3292 KiB
8Accepted2/24ms3500 KiB
9Accepted2/24ms3456 KiB
10Accepted2/24ms3448 KiB
11Accepted2/24ms3516 KiB
12Accepted2/29ms3720 KiB
13Accepted3/326ms3768 KiB
14Accepted3/36ms3704 KiB
15Accepted3/326ms3984 KiB
16Accepted3/34ms3896 KiB
17Accepted3/323ms4052 KiB
18Accepted3/39ms4004 KiB
19Accepted3/33ms4248 KiB
20Accepted3/33ms4472 KiB
21Accepted3/310ms4720 KiB
22Accepted3/354ms4824 KiB