252292026-02-18 17:19:54szabel26Kaktuszgráfcpp17Accepted 50/502ms508 KiB
// kaktuszgraf.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
using namespace std;

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

int n, m, a, b, max_hossz;
vector<adat>x;

void melysegi(int akt)
{
    for (auto& e : x[akt].sz)
    {
        if (x[e].lat == 1 && x[akt].honnan != e)
        {
            max_hossz = max(max_hossz, x[akt].lep - x[e].lep + 1);
        }
        if (!x[e].lat)
        {
            x[e].honnan = akt;
            x[e].lep = x[akt].lep + 1;
            x[e].lat = 1;
            melysegi(e);
        }
    }
}

int main()
{
    cin >> n >> m;
    x.resize(n + 1);

    for (int i = 1; i <= m; ++i)
    {
        cin >> a >> b;
        x[a].sz.push_back(b);
        x[b].sz.push_back(a);
    }

    x[1].lep = 0;
    x[1].honnan = 0;
    x[1].lat = 1;
    melysegi(1);

    cout << max_hossz;
}

// 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/01ms316 KiB
3Accepted2/21ms316 KiB
4Accepted2/22ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/22ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/22ms316 KiB
9Accepted2/22ms320 KiB
10Accepted2/22ms316 KiB
11Accepted2/22ms316 KiB
12Accepted2/22ms316 KiB
13Accepted2/22ms316 KiB
14Accepted2/22ms316 KiB
15Accepted2/22ms316 KiB
16Accepted2/22ms508 KiB
17Accepted2/22ms316 KiB
18Accepted2/22ms500 KiB
19Accepted3/32ms316 KiB
20Accepted3/31ms316 KiB
21Accepted3/32ms316 KiB
22Accepted3/32ms316 KiB
23Accepted3/32ms316 KiB
24Accepted3/32ms316 KiB