36332023-03-01 12:40:01EyusieKaktuszgráfcpp17Accepted 50/504ms4432 KiB
#include <bits/stdc++.h>
using namespace std;

vector<vector<int>> el;
map<int, int> eloford;
vector<bool> volt;
int legnagyk;

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

int main()
{
    int n, m;
    cin >> n >> m;
    volt.assign(n, false);
    el.assign(n, vector<int>());
    for(int i = 0, kap, kapcs; i < m; i++)
    {
        cin >> kap >> kapcs;
        kap--;
        kapcs--;
        el[kap].push_back(kapcs);
        el[kapcs].push_back(kap);
    }
    dfs(0, 0);
    cout << legnagyk;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1808 KiB
2Accepted0/03ms2244 KiB
3Accepted2/23ms2460 KiB
4Accepted2/23ms2728 KiB
5Accepted2/23ms2948 KiB
6Accepted2/24ms3064 KiB
7Accepted2/24ms3244 KiB
8Accepted2/24ms3428 KiB
9Accepted2/24ms3372 KiB
10Accepted2/24ms3540 KiB
11Accepted2/24ms3620 KiB
12Accepted2/24ms3820 KiB
13Accepted2/24ms4032 KiB
14Accepted2/24ms3984 KiB
15Accepted2/24ms4248 KiB
16Accepted2/24ms4196 KiB
17Accepted2/24ms4212 KiB
18Accepted2/24ms4204 KiB
19Accepted3/34ms4204 KiB
20Accepted3/34ms4392 KiB
21Accepted3/34ms4432 KiB
22Accepted3/34ms4428 KiB
23Accepted3/34ms4428 KiB
24Accepted3/34ms4424 KiB