23752023-01-11 21:18:15TuruTamasCiklikus rácsháló gráfcpp11Elfogadva 40/4024ms5116 KiB
#include <bits/stdc++.h>
using namespace std;


#define InTheNameOfGod cin.tie(0); cout.tie(0); ios::sync_with_stdio(0);
#define nl '\n'

void print(vector<vector<int>> &s);


int N, M, K, maxx = INT_MAX, L = 500;

void arg(vector<vector<int>> &s, int a, int b) {
    // for (size_t k = 0; k < N*M; k++)
    // {
        
        for (size_t i = 0; i < N*M; i++)
        {
            for (size_t j = 0; j < N*M; j++)
            {
                s[i][j] = min(s[i][a] + s[j][b] + 1, s[i][j]);
                s[i][j] = min(s[i][b] + s[j][a] + 1, s[i][j]);
            } // j
        } // i
    // } // k

    int temp = -1, t;
    for(auto &i : s)
    {
        t = *max_element(i.begin(), i.end());
        temp = t > temp ? t : temp;
    }
    maxx = temp;
    // cout << "KESZ AZ ARGS\n";
    // print(s);
}

void fulld(vector<vector<int>> &s) {
    for (size_t k = 0; k < N*M; k++)
    {
        for (size_t i = 0; i < N*M; i++)
        {
            for (size_t j = 0; j < N*M; j++)
            {
                s[i][j] = min(s[i][k] + s[k][j], s[i][j]);
            } // j
        } // i
    } // k

    int temp = -1, t;
    for(auto &i : s)
    {
        t = *max_element(i.begin(), i.end());
        temp = t > temp ? t : temp;
    }
    maxx = temp;
    // cout << "KESZ AZ ARGS\n";
    // print(s);

}

void print(vector<vector<int>> &s)
{
    cout << "-----\n     ";
    for (size_t i = 0; i < M*N; i++)
    {
        cout << setw(3) << i << ' ';
    }
    cout << nl <<nl;
    for (size_t i = 0; i < N*M; i++)
    {
        cout << setw(3) << i << "  ";
        for (size_t k = 0; k < N*M; k++)
        {
            cout << setw(3) << s[i][k] << " ";
        }
        cout << setw(3) << i << "\n";
    }
    cout << "-----\n";
}

int main() {

    InTheNameOfGod

    cin >> N >> M >> K;
    vector<vector<int>> s(N*M, vector<int>(N*M, L));

    // cout << "d0\n";

    for (size_t i = 0; i < N*M; i++)
    {
        int sor = i / M;
        int osz = i % M;
        // cout << i << " -> " << sor << ":" << osz << "\n";
        if (sor != 0) {
            // cout << "d1\n";
            s[i - M][i] = 1;
            s[i][i - M] = 1;
            // cout << "d2\n";
        }
        if (osz != 0) {
            // cout << "d3\n";
            s[i][i - 1] = 1;
            s[i - 1][i] = 1;
            // cout << "d4\n";
        }
        if (sor != N - 1) {
            // cout << "d5\n";
            s[i][i + M] = 1;
            s[i + M][i] = 1;
            // cout << "d6\n";
        }
        if (osz != M - 1) {
            // cout << "d7\n";
            s[i + 1][i] = 1;
            s[i][i + 1] = 1;
            // cout << "d8\n";
        }
        // cout << "d9\n";
        s[i][i] = 0;
    }
    if(N > 1 && M > 1)
    {
        for(int i = 0; i < N; i++)
        {
            s[i*M][i*M+M-1] = 1;
            s[i*M+M-1][i*M] = 1;
        }
        for(int i = 0; i < M; i++)
        {
            s[i][M*(N-1)+i] = 1;
            s[M*(N-1)+i][i] = 1;
        }
    }
    else if(N > 1)
    {
        s[0][N-1] = 1;
        s[N-1][0] = 1;
    }
    else if(M > 1)
    {
        s[0][M-1] = 1;
        s[M-1][0] = 1;
    }
    fulld(s);
    // print(s);
    int a, b;
    for (size_t i = 0; i <K; i++)
    {
        cin >> a >> b;
        a--;
        b--;
        s[a][b] = 1;
        s[b][a] = 1;
        arg(s, a, b);
        // print(s);
        cout << maxx << "\n";
    }
    // print(s);
    
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base40/40
1Elfogadva0/03ms1824 KiB
2Elfogadva0/024ms2408 KiB
3Elfogadva2/22ms2228 KiB
4Elfogadva2/22ms2436 KiB
5Elfogadva2/22ms2636 KiB
6Elfogadva2/22ms2716 KiB
7Elfogadva2/24ms3008 KiB
8Elfogadva2/24ms3208 KiB
9Elfogadva2/24ms3160 KiB
10Elfogadva2/23ms3260 KiB
11Elfogadva2/24ms3368 KiB
12Elfogadva2/217ms3904 KiB
13Elfogadva2/210ms3624 KiB
14Elfogadva2/24ms3832 KiB
15Elfogadva2/210ms4188 KiB
16Elfogadva2/24ms3976 KiB
17Elfogadva2/28ms4008 KiB
18Elfogadva2/24ms4236 KiB
19Elfogadva2/22ms4200 KiB
20Elfogadva2/22ms4300 KiB
21Elfogadva2/24ms4676 KiB
22Elfogadva2/224ms5116 KiB