39822023-03-07 13:44:34tamasmarkKaktuszgráfcpp17Elfogadva 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
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/03ms2068 KiB
2Elfogadva0/04ms6192 KiB
3Elfogadva2/24ms6908 KiB
4Elfogadva2/24ms7672 KiB
5Elfogadva2/24ms8632 KiB
6Elfogadva2/24ms9560 KiB
7Elfogadva2/24ms10596 KiB
8Elfogadva2/24ms10576 KiB
9Elfogadva2/26ms11148 KiB
10Elfogadva2/26ms11124 KiB
11Elfogadva2/26ms11232 KiB
12Elfogadva2/26ms11176 KiB
13Elfogadva2/26ms11336 KiB
14Elfogadva2/26ms11584 KiB
15Elfogadva2/26ms11432 KiB
16Elfogadva2/26ms11656 KiB
17Elfogadva2/26ms11820 KiB
18Elfogadva2/26ms11828 KiB
19Elfogadva3/36ms11972 KiB
20Elfogadva3/36ms12340 KiB
21Elfogadva3/36ms12396 KiB
22Elfogadva3/36ms12380 KiB
23Elfogadva3/36ms12676 KiB
24Elfogadva3/34ms12852 KiB