244302026-02-11 15:26:44tamasnagyKaktuszgráfcpp17Accepted 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
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms500 KiB
2Accepted0/01ms492 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/21ms316 KiB
9Accepted2/21ms316 KiB
10Accepted2/21ms316 KiB
11Accepted2/21ms316 KiB
12Accepted2/21ms484 KiB
13Accepted2/21ms316 KiB
14Accepted2/21ms500 KiB
15Accepted2/21ms316 KiB
16Accepted2/21ms316 KiB
17Accepted2/21ms316 KiB
18Accepted2/22ms384 KiB
19Accepted3/31ms316 KiB
20Accepted3/31ms316 KiB
21Accepted3/31ms316 KiB
22Accepted3/31ms316 KiB
23Accepted3/31ms476 KiB
24Accepted3/31ms496 KiB