63502023-11-23 19:05:29MrChipserRácsháló gráfcpp11Wrong answer 0/5029ms4412 KiB
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
int n,m,k;
int csm[200][200];

int bfs()
{
    int mtav = 0;
    int votma[n*m]={0};
    int tav[n*m] = {0};
    queue<int>q;
    q.push(0);
    votma[0]=1;
    while(!q.empty())
    {
        int akt = q.front();
        //cout << akt << " ";
        q.pop();
        for(int i = 0; i <n*m; i++)
        {
            if(csm[akt][i]==1 && votma[i]==0)
            {
                q.push(i);
                votma[i]=1;
                tav[i]=tav[akt]+1;
                cout << tav[i] << " " << tav[akt] << " " << i  << " " << akt<< endl;
                if(tav[i]>mtav)
                    mtav=tav[i];
            }
        }
    }
    //for(int i = 0; i < n*m; i++)
     //   cout << tav[i] << " ";
    cout << endl;
    return mtav;
}

int main()
{
    cin >> n >> m >> k;
    for(int i = 0; i < n*m; i++)
        for(int j = 0; j < n*m; j++)
            csm[i][j]=0;
    for(int i = 0; i < n*m; i++)
    {
        if(i < n*m-m)
        {
            csm[i][i+m]=1;
            csm[i+m][i]=1;
        }
        if((i+1)%m!=0)
        {
            cout << i << endl;
            csm[i][i+1]=1;
            csm[i+1][i]=1;
        }
    }
    for(int i = 0; i < n*m; i++)
    {
        for(int j = 0; j < n*m; j++)
            cout << csm[i][j];
        cout << endl;
    }
    vector<int>maxut;
    for(int i = 0; i < k; i++)
    {
        int x,y;
        cin >> x >> y;
        csm[x-1][y-1]=1;
        csm[y-1][x-1]=1;
        maxut.push_back(bfs());

    }
    for(int i = 0; i < maxut.size(); i++)
        cout << maxut[i] << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/03ms1828 KiB
2Wrong answer0/029ms2288 KiB
3Wrong answer0/23ms2248 KiB
4Wrong answer0/23ms2460 KiB
5Wrong answer0/23ms2556 KiB
6Wrong answer0/23ms2816 KiB
7Wrong answer0/24ms2832 KiB
8Wrong answer0/24ms2832 KiB
9Wrong answer0/24ms2840 KiB
10Wrong answer0/24ms2816 KiB
11Wrong answer0/26ms3104 KiB
12Wrong answer0/213ms3604 KiB
13Wrong answer0/319ms3552 KiB
14Wrong answer0/37ms3360 KiB
15Wrong answer0/314ms3660 KiB
16Wrong answer0/36ms3716 KiB
17Wrong answer0/313ms3896 KiB
18Wrong answer0/38ms3808 KiB
19Wrong answer0/33ms3828 KiB
20Wrong answer0/34ms4096 KiB
21Wrong answer0/38ms4160 KiB
22Wrong answer0/321ms4412 KiB