153972025-02-19 11:28:48markfsibianRácsháló gráfcpp17Wrong answer 7/503ms508 KiB
#include <iostream>
#include <vector>
#include <deque>
#include <climits>
#include <algorithm>

using namespace std;

struct pont
{
    int lat, lep;
    vector<int> sz;
};

vector<pont> v;
deque<int> wl;

int szel(vector<pont> v, deque<int> wl, int ke)
{
    int akt, mini = INT_MIN;
    v[ke].lat = 1;
    v[ke].lep = 0;
    wl.push_back(ke);

    while (!wl.empty())
    {
        akt = wl.front();
        wl.pop_front();
        for (auto& e : v[akt].sz)
        {
            if (!v[e].lat)
            {
                wl.push_back(e);
                v[e].lat = 1;
                v[e].lep = v[akt].lep + 1;
                if (v[e].lep > mini)
                    mini = v[e].lep;
            }
        }
    }
    return mini;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int so, os, uj, n, a, b, k = 1;
    cin >> so >> os >> uj;
    n = so * os;

    v.resize(n + 1);

    for (int i = 1; i <= so; ++i)
        for (int j = 1; j <= os; ++j)
        {
            if (j < os)
            {
                v[k].sz.push_back(k + 1);
                v[k + 1].sz.push_back(k);
            }
            if (i < so)
            {
                v[k].sz.push_back(os * i + j);
                v[os * i + j].sz.push_back(k);
            }
            k++;
        }


    for (int i = 1; i <= uj; ++i)
    {
        cin >> a >> b;
        v[a].sz.push_back(b);
        v[b].sz.push_back(a);
        cout << max(szel(v, wl, 1), szel(v, wl, os)) << endl;
    }

}
SubtaskSumTestVerdictTimeMemory
base7/50
1Accepted0/01ms316 KiB
2Wrong answer0/03ms508 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Wrong answer0/21ms316 KiB
6Wrong answer0/21ms508 KiB
7Wrong answer0/21ms316 KiB
8Wrong answer0/21ms508 KiB
9Wrong answer0/21ms316 KiB
10Wrong answer0/21ms316 KiB
11Wrong answer0/21ms508 KiB
12Wrong answer0/21ms316 KiB
13Wrong answer0/32ms316 KiB
14Wrong answer0/31ms316 KiB
15Wrong answer0/32ms316 KiB
16Wrong answer0/31ms316 KiB
17Accepted3/32ms316 KiB
18Wrong answer0/32ms316 KiB
19Wrong answer0/31ms316 KiB
20Wrong answer0/31ms316 KiB
21Wrong answer0/32ms504 KiB
22Wrong answer0/33ms316 KiB