244302026-02-11 15:26:44tamasnagyKaktuszgráfcpp17Elfogadva 50/502ms500 KiB
// kakagraf.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
using namespace std;
vector<vector<int>>szl;
vector<int>jart;
vector<int>tav;
int n, m;
int maxh;
void dfs(int kcs=1) {
    jart[kcs] = 1;
    for (int i = 0; i < szl[kcs].size(); i++) {
        if (jart[szl[kcs][i]] == 0) {
            tav[szl[kcs][i]] = tav[kcs] + 1;
            dfs(szl[kcs][i]);
        }
        else {
            if (tav[kcs] - tav[szl[kcs][i]] > maxh) {
                maxh = tav[kcs] - tav[szl[kcs][i]];
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    szl.resize(n + 1);
    jart.resize(n + 1);
    tav.resize(n + 1);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;;
        szl[a].push_back(b);
        szl[b].push_back(a);
    }
    dfs();
    cout << maxh+1;
}

// 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/01ms500 KiB
2Elfogadva0/01ms492 KiB
3Elfogadva2/21ms316 KiB
4Elfogadva2/21ms316 KiB
5Elfogadva2/21ms316 KiB
6Elfogadva2/21ms316 KiB
7Elfogadva2/21ms316 KiB
8Elfogadva2/21ms316 KiB
9Elfogadva2/21ms316 KiB
10Elfogadva2/21ms316 KiB
11Elfogadva2/21ms316 KiB
12Elfogadva2/21ms484 KiB
13Elfogadva2/21ms316 KiB
14Elfogadva2/21ms500 KiB
15Elfogadva2/21ms316 KiB
16Elfogadva2/21ms316 KiB
17Elfogadva2/21ms316 KiB
18Elfogadva2/22ms384 KiB
19Elfogadva3/31ms316 KiB
20Elfogadva3/31ms316 KiB
21Elfogadva3/31ms316 KiB
22Elfogadva3/31ms316 KiB
23Elfogadva3/31ms476 KiB
24Elfogadva3/31ms496 KiB