36302023-03-01 12:22:36EyusieKaktuszgráfcpp17Accepted 50/504ms4676 KiB
#include <bits/stdc++.h>
using namespace std;

vector<bool> volt;
vector<vector<int>> el;
map<int, int> sor;
int legnagykor;

void dfs(int akt, int hely)
{
    int aktkorm;
    volt[akt] = true;
    sor[akt] = hely;
    for(int kov : el[akt])
    {
        if(volt[kov])
        {
            aktkorm = hely - sor[kov] + 1;
            legnagykor = max(aktkorm, legnagykor);
        }
        else
        {
            dfs(kov, hely+1);
        }
    }
}

int main()
{

    int n, m, kap, kapcs;
    cin >> n >> m;
    volt.assign(n, false);
    el.assign(n, vector<int>());

    for(int i = 0; i < m; i++)
    {
        cin >> kap >> kapcs;
        kap--;
        kapcs--;
        el[kap].push_back(kapcs);
        el[kapcs].push_back(kap);
    }
    dfs(0, 0);

    cout << legnagykor;

}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1812 KiB
2Accepted0/03ms2240 KiB
3Accepted2/23ms2560 KiB
4Accepted2/23ms2680 KiB
5Accepted2/23ms2524 KiB
6Accepted2/24ms2792 KiB
7Accepted2/24ms3048 KiB
8Accepted2/24ms3220 KiB
9Accepted2/24ms3488 KiB
10Accepted2/24ms3704 KiB
11Accepted2/24ms3852 KiB
12Accepted2/24ms4072 KiB
13Accepted2/24ms4116 KiB
14Accepted2/24ms4012 KiB
15Accepted2/24ms3988 KiB
16Accepted2/24ms3992 KiB
17Accepted2/24ms4244 KiB
18Accepted2/24ms4508 KiB
19Accepted3/34ms4524 KiB
20Accepted3/34ms4604 KiB
21Accepted3/34ms4640 KiB
22Accepted3/34ms4640 KiB
23Accepted3/34ms4676 KiB
24Accepted3/34ms4640 KiB