23612023-01-11 12:40:17rennCiklikus rácsháló gráfcpp11Time limit exceeded 6/40600ms4280 KiB
#include <bits/stdc++.h>
using namespace std;


#define InTheNameOfGod cin.tie(0); ios::sync_with_stdio(0);


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

void arg(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";

}

void print(vector<vector<int>> s)
{
    cout << "-----\n";
    for (size_t i = 0; i < N*M; i++)
    {
        for (size_t j = 0; j < N*M; j++)
        {
            if(s[i][j] > 300)
                cout << "z ";
            else
                cout << s[i][j] << ' ';
        }
        cout << "\n\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 / N;

        // 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;
    }

    for(int i = 0; i < N; i++)
    {
        s[i*M][M-1] = 1;
        s[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;
    }

    // print(s);

    arg(s);

    size_t a, b;
    for (size_t i = 0; i < K; i++)
    {
        // print(s);
        cin >> a >> b;
        a--;
        b--;
        s[a][b] = 1;
        s[b][a] = 1;
        // cout << maxx << "\n";
        arg(s);
        cout << maxx << "\n";
    }
    // print(s);
    
}
SubtaskSumTestVerdictTimeMemory
base6/40
1Accepted0/03ms1828 KiB
2Time limit exceeded0/0600ms1732 KiB
3Wrong answer0/22ms2296 KiB
4Accepted2/22ms2472 KiB
5Wrong answer0/23ms2672 KiB
6Accepted2/23ms2896 KiB
7Wrong answer0/220ms3396 KiB
8Wrong answer0/220ms3204 KiB
9Wrong answer0/220ms3484 KiB
10Wrong answer0/27ms3380 KiB
11Accepted2/220ms3496 KiB
12Wrong answer0/2190ms4280 KiB
13Wrong answer0/2230ms3936 KiB
14Wrong answer0/226ms3640 KiB
15Wrong answer0/2224ms3888 KiB
16Wrong answer0/221ms3932 KiB
17Wrong answer0/2170ms4040 KiB
18Wrong answer0/239ms4136 KiB
19Wrong answer0/23ms4024 KiB
20Wrong answer0/24ms4036 KiB
21Wrong answer0/252ms4144 KiB
22Time limit exceeded0/2574ms3712 KiB