2472021-03-05 16:07:02balintttKaktuszgráfcpp14Accepted 50/503ms2248 KiB
#include<bits/stdc++.h>

using namespace std;

class pont{
public:
    vector<int> hova;
    int index;
    void dfs(int dep);
    bool volt = 0;
    int dept;
};

int n, m, a, b;

vector<pont> p;

//int tav[1000];

int er = 0;

void pont::dfs(int dep){
    if(volt){
        //cout << index << ' ' << ' ' << tav[index] << '\n';
        er = max(er, dep-dept+1);
    } else {
        dept = dep;
        /*cout << index << ':';
        for(int i=0;i<n;i++){
            cout << tav[i] << ' ';
        }
        cout << '\n';*/
        //tav[index] = 1;
        volt = 1;
        //cout << index << ' ' << hova.size() << '\n';
        for(int i : hova){
            //cout << index << ' ' << i << '\n';
            p[i].dfs(dep+1);
        }
        //tav[index] = 0;
        //for(int i=0;i<n;i++){
        //    if(tav[i] != 0) --tav[i];
        //}
    }
}

int main(){
    cin >> n >> m;
    p.resize(n);
    for(int i=0;i<n;i++){
        p[i].index=i;
    }
    for(int i=0;i<m;i++){
        cin >> a >> b;
        --a; --b;
        p[a].hova.push_back(b);
        p[b].hova.push_back(a);
    }
    p[0].dfs(0);
    cout << er-1 << '\n';
return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/02ms1800 KiB
2Accepted0/02ms1868 KiB
3Accepted2/22ms1944 KiB
4Accepted2/22ms1964 KiB
5Accepted2/22ms1980 KiB
6Accepted2/23ms1992 KiB
7Accepted2/22ms2028 KiB
8Accepted2/22ms2020 KiB
9Accepted2/22ms2028 KiB
10Accepted2/22ms2040 KiB
11Accepted2/22ms2052 KiB
12Accepted2/23ms2068 KiB
13Accepted2/22ms2076 KiB
14Accepted2/22ms2088 KiB
15Accepted2/22ms2104 KiB
16Accepted2/23ms2116 KiB
17Accepted2/23ms2128 KiB
18Accepted2/22ms2148 KiB
19Accepted3/32ms2160 KiB
20Accepted3/32ms2200 KiB
21Accepted3/32ms2220 KiB
22Accepted3/32ms2228 KiB
23Accepted3/32ms2232 KiB
24Accepted3/32ms2248 KiB