89662024-02-09 07:56:58RRoliKaktuszgráfcpp17Accepted 50/504ms5560 KiB
#include <iostream>
#include <cmath>
using namespace std;

int n, m, L[1001], ln = 2;
bool a[1001][1001];

void bejar(int k) {
    for(int i = 1; i <= n; i++) {
        if(a[k][i]) {
            if(L[i] == -1) {
                L[i] = L[k]+1;
                bejar(i);
            } else if(abs(L[i] - L[k])+1 > ln)
                ln = abs(L[i] - L[k])+1;
        }
    }
}

int main()
{
    cin >> n >> m;
    for(int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        a[x][y] = true; a[y][x] = true;
    }

    for(int i = 1; i <= n; i++) L[i] = -1;
    L[1] = 0;
    bejar(1);
    cout << ln;

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1896 KiB
2Accepted0/03ms3088 KiB
3Accepted2/24ms3536 KiB
4Accepted2/24ms4032 KiB
5Accepted2/24ms4180 KiB
6Accepted2/24ms4428 KiB
7Accepted2/24ms4804 KiB
8Accepted2/24ms5048 KiB
9Accepted2/24ms4920 KiB
10Accepted2/24ms5060 KiB
11Accepted2/24ms4960 KiB
12Accepted2/24ms5100 KiB
13Accepted2/24ms5096 KiB
14Accepted2/24ms5116 KiB
15Accepted2/24ms5132 KiB
16Accepted2/24ms5416 KiB
17Accepted2/24ms5324 KiB
18Accepted2/24ms5256 KiB
19Accepted3/34ms5268 KiB
20Accepted3/34ms5448 KiB
21Accepted3/34ms5456 KiB
22Accepted3/34ms5472 KiB
23Accepted3/34ms5472 KiB
24Accepted3/34ms5560 KiB