36292023-03-01 12:20:44EyusieKaktuszgráfcpp17Time limit exceeded 33/50246ms4532 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] && sor.count(kov))
        {
            aktkorm = hely - sor[kov] + 1;
            legnagykor = max(aktkorm, legnagykor);
        }
        else
        {
            dfs(kov, hely+1);
        }
    }
    sor.erase(akt);
}

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
base33/50
1Accepted0/03ms1808 KiB
2Accepted0/06ms2180 KiB
3Accepted2/216ms2392 KiB
4Accepted2/229ms2608 KiB
5Accepted2/239ms2828 KiB
6Time limit exceeded0/2162ms2752 KiB
7Accepted2/24ms3100 KiB
8Accepted2/24ms3256 KiB
9Accepted2/2114ms3216 KiB
10Time limit exceeded0/2165ms3492 KiB
11Time limit exceeded0/2151ms3700 KiB
12Time limit exceeded0/2180ms3768 KiB
13Time limit exceeded0/2246ms3728 KiB
14Accepted2/243ms3752 KiB
15Time limit exceeded0/2159ms3640 KiB
16Time limit exceeded0/2163ms3604 KiB
17Accepted2/250ms3700 KiB
18Accepted2/250ms3632 KiB
19Time limit exceeded0/3238ms3600 KiB
20Accepted3/34ms3968 KiB
21Accepted3/34ms4236 KiB
22Accepted3/34ms4444 KiB
23Accepted3/34ms4404 KiB
24Accepted3/34ms4532 KiB