8292022-01-18 21:44:26Halasz EszterCiklikus rácsháló gráfcpp11Accepted 40/4057ms2220 KiB
#include <iostream>
//#include <fstream>
#include <algorithm>
#include <deque>
#include <vector>

using namespace std;

//ifstream cin("ciklikusracshalograf.in");
//ofstream cout("ciklikusracshalograf.out");

deque<int>y;

struct adat
{
    int x,y;
};
adat a,b,q;

struct adat2
{
    int lat,lep;
    vector<int>sz;
};
vector<adat2>x;

int i,j,n,m,k,maxii=-9999,aa,bb;

void maxi(int a)
{
    int i;
    for(i=1;i<=n*m;++i)
    if(x[i].lep>maxii) maxii=x[i].lep;
    for(i=1;i<=n*m;++i) 
    {
        x[i].lat=0;
    }
}
void szelessegi(int i)
{
    int csp=0;
    y.push_back(i);
    x[i].lep=0;
    while(!y.empty())
    {
        csp=y.front();
        y.pop_front();
        for(auto e:x[csp].sz)
        {
            if(x[e].lat==0)
            {
                x[e].lat=1;
                x[e].lep=x[csp].lep+1;
                y.push_back(e);
            }
            else x[e].lep=min(x[e].lep,x[csp].lep+1);
        }
    }
}
int main()
{
    cin>>n>>m>>k;
    x.resize(n*m+1);
    for(i=1;i<=n*m;++i)
    {
        for(j=1;j<=n*m;++j)
        if(j>i)
        {
           if(i%m!=0) a.x=i/m+1;
           else a.x=i/m;

            if(j%m!=0) b.x=j/m+1;
            else b.x=j/m;
            
            a.y=i%m;
            if(a.y==0) a.y=m;
            
            b.y=j%m;
            if(b.y==0) b.y=m;

            if((a.y==1 && b.y==m && b.x==a.x) || (a.y==b.y && a.x==1 && b.x==n) || (abs(a.x-b.x)+abs(a.y-b.y)==1)) 
            {
                x[i].sz.push_back(j);
                x[j].sz.push_back(i);
            }
        }

    }

    while(k)
    {
        cin>>aa>>bb;
        x[aa].sz.push_back(bb);
        x[bb].sz.push_back(aa);
             maxii=-9999;
        for(i=1;i<=n*m;++i)
        {
            szelessegi(i);
       
            maxi(aa);
           
        }
         cout<<maxii<<"\n";
        k--;
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms2108 KiB
2Accepted0/057ms2116 KiB
3Accepted2/21ms2136 KiB
4Accepted2/21ms2140 KiB
5Accepted2/22ms2144 KiB
6Accepted2/22ms2144 KiB
7Accepted2/24ms2156 KiB
8Accepted2/23ms2160 KiB
9Accepted2/24ms2164 KiB
10Accepted2/22ms2164 KiB
11Accepted2/24ms2168 KiB
12Accepted2/212ms2176 KiB
13Accepted2/230ms2180 KiB
14Accepted2/24ms2188 KiB
15Accepted2/227ms2188 KiB
16Accepted2/24ms2192 KiB
17Accepted2/223ms2200 KiB
18Accepted2/29ms2200 KiB
19Accepted2/22ms2204 KiB
20Accepted2/22ms2204 KiB
21Accepted2/210ms2216 KiB
22Accepted2/257ms2220 KiB