141932025-01-10 08:44:10csdavidRácsháló gráfcpp17Accepted 50/507ms756 KiB
#include <iostream>
//#include <fstream>

using namespace std;

int main()
{
    //ifstream fin("be2.txt");
    int n, m, k, x=0, y;
    cin >> n >> m >> k;
    pair<int, int> b[m*n];
    int a[m*n][m*n];
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            b[x].first=i;
            b[x].second=j;
            x++;
        }
    }
    int mintav=0;
    for(int i=0; i<m*n; i++){
        for(int j=0; j<m*n; j++){
            a[i][j]=abs(b[i].first-b[j].first)+abs(b[i].second-b[j].second);
            if(a[i][j]>mintav){
                mintav=a[i][j];
            }
        }
    }
    /*for(int i1=0; i1<m*n; i1++){
        for(int j1=0; j1<m*n; j1++){
            cout << i1+1 << " -> " << j1+1 << " = " << a[i1][j1] << '\n';
        }
    }*/
    while(k--){
            //cout << "\n\n";
        cin >> x >> y;
        x--;
        y--;
        a[x][y]=1;
        a[y][x]=1;
        for(int i=0; i<m*n; i++){
            for(int j=i+1; j<m*n; j++){
                a[i][j]=min(a[i][j], min(a[i][x]+a[y][j]+1, a[j][x]+a[y][i]+1));
                a[j][i]=a[i][j];
            }
        }
        int maxi=-1;
        for(int i=0; i<n*m; i++){
            for(int j=0; j<n*m; j++){
                maxi=max(a[i][j], maxi);
            }
        }
        cout << maxi << '\n';
        /*for(int i1=0; i1<m*n; i1++){
            for(int j1=0; j1<m*n; j1++){
                cout << i1+1 << " -> " << j1+1 << " = " << a[i1][j1] << '\n';
            }
        }*/
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms316 KiB
2Accepted0/07ms512 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/21ms316 KiB
9Accepted2/21ms316 KiB
10Accepted2/21ms316 KiB
11Accepted2/21ms316 KiB
12Accepted2/23ms756 KiB
13Accepted3/34ms316 KiB
14Accepted3/31ms316 KiB
15Accepted3/34ms316 KiB
16Accepted3/31ms436 KiB
17Accepted3/33ms316 KiB
18Accepted3/32ms316 KiB
19Accepted3/31ms508 KiB
20Accepted3/31ms316 KiB
21Accepted3/32ms316 KiB
22Accepted3/37ms428 KiB