39822023-03-07 13:44:34tamasmarkKaktuszgráfcpp17Accepted 50/506ms12852 KiB
// kaktuszgraf.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <deque>
#include <cmath>

using namespace std;

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

int n, a, b, i, maxi,bejart[1001][1001],m;
vector<adat>x;
void melysegi(int csp)
{
    x[csp].lat = 1;
    for (auto& e : x[csp].sz)
    {
        if (!x[e].lat)
        {
            bejart[csp][e] = bejart[e][csp] = 1;
            x[e].tav = x[csp].tav + 1;
            melysegi(e);
        }
        else
        {
            if (!bejart[csp][e])
            {
                if (maxi < abs(x[csp].tav - x[e].tav) + 1)
                    maxi = abs(x[csp].tav - x[e].tav) + 1;
            }
            else bejart[csp][e] = bejart[e][csp] = 1;
        }
    }
}

int main()
{
    cin >> n >> m;
    x.resize(n + 1);
    for(i = 1; i <= m; ++i)
    {
        cin >> a >> b;
        x[a].sz.push_back(b);
        x[b].sz.push_back(a);
    }
    melysegi(1);
    cout << maxi;

    return 0;
}
/*
13 15
1 3
1 4
2 3
3 5
4 5
4 12
12 13
13 4
5 7
7 6
7 11
6 8
11 10
10 9
8 9

*/
// 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/03ms2068 KiB
2Accepted0/04ms6192 KiB
3Accepted2/24ms6908 KiB
4Accepted2/24ms7672 KiB
5Accepted2/24ms8632 KiB
6Accepted2/24ms9560 KiB
7Accepted2/24ms10596 KiB
8Accepted2/24ms10576 KiB
9Accepted2/26ms11148 KiB
10Accepted2/26ms11124 KiB
11Accepted2/26ms11232 KiB
12Accepted2/26ms11176 KiB
13Accepted2/26ms11336 KiB
14Accepted2/26ms11584 KiB
15Accepted2/26ms11432 KiB
16Accepted2/26ms11656 KiB
17Accepted2/26ms11820 KiB
18Accepted2/26ms11828 KiB
19Accepted3/36ms11972 KiB
20Accepted3/36ms12340 KiB
21Accepted3/36ms12396 KiB
22Accepted3/36ms12380 KiB
23Accepted3/36ms12676 KiB
24Accepted3/34ms12852 KiB