196032025-12-16 17:27:57szabelrRácsháló gráfcpp17Accepted 50/507ms684 KiB
// Rácsháló gráf.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <climits>

using namespace std;
int dist[201][201];
int main()
{
    int n, m, k;
    cin >> n >> m>>k;
    
    for (int i = 1; i <= n*m; i++)
    {
        for (int j = 1; j <=n*m; j++)
        {
            dist[i][j]= abs((i - 1) / m - (j - 1) / m) + abs((i - 1) % m - (j - 1) % m);
        }
    }
    for (int z = 0; z < k; z++)
    {
        int a, b;
        cin >> a >> b;
        dist[a][b] = 1;
        dist[b][a] = 1;
        for (int i = 1; i <= m * n; i++)
        {
            for (int j = 1; j <= m * n; j++)
            {
                int p1 = dist[i][a] + 1 + dist[b][j];
                int p2 = dist[i][b] + 1 + dist[a][j];
                dist[i][j] = min(dist[i][j], min(p1, p2));
            }
        }
        int maxi = INT_MIN;
        for (int i = 1; i <= m*n; i++) {
            for (int j = 1; j <= m * n; j++) {
                maxi = max(dist[i][j], maxi);
            }
        }
        cout << maxi << endl;
    }

}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms316 KiB
2Accepted0/07ms564 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Accepted2/22ms316 KiB
8Accepted2/21ms316 KiB
9Accepted2/21ms684 KiB
10Accepted2/21ms500 KiB
11Accepted2/21ms500 KiB
12Accepted2/23ms564 KiB
13Accepted3/34ms424 KiB
14Accepted3/31ms316 KiB
15Accepted3/34ms316 KiB
16Accepted3/31ms316 KiB
17Accepted3/33ms316 KiB
18Accepted3/32ms316 KiB
19Accepted3/31ms344 KiB
20Accepted3/31ms540 KiB
21Accepted3/32ms316 KiB
22Accepted3/37ms344 KiB