94412024-02-21 17:50:53NagyLeoKaktuszgráfpython3Accepted 50/5021ms15736 KiB
from sys import stdin, stdout, setrecursionlimit
input=stdin.readline

setrecursionlimit(10**5)
def main():
    N, M = map(int, input().split())
    graph = [[] for i in range(N+1)]

    for i in range(M):
        A, B = map(int, input().split())
        graph[A].append(B)
        graph[B].append(A)
    #print(graph)

    lenCircle=0
    seen = {1:0}



    def depth_search(node, lenCircle):
        for v in graph[node]:
            if v not in seen:
                seen[v] = seen[node]+1
                lenCircle=depth_search(v, lenCircle)
            else:
                lenCircle = max(seen[node]-seen[v]+1, lenCircle)
        return lenCircle

    print(depth_search(1,lenCircle))


main()
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/017ms11388 KiB
2Accepted0/019ms11592 KiB
3Accepted2/219ms12056 KiB
4Accepted2/219ms12416 KiB
5Accepted2/219ms12604 KiB
6Accepted2/220ms12888 KiB
7Accepted2/220ms13412 KiB
8Accepted2/220ms13316 KiB
9Accepted2/220ms13508 KiB
10Accepted2/220ms13372 KiB
11Accepted2/220ms13312 KiB
12Accepted2/220ms13332 KiB
13Accepted2/220ms13280 KiB
14Accepted2/220ms13192 KiB
15Accepted2/220ms13276 KiB
16Accepted2/220ms13484 KiB
17Accepted2/220ms13656 KiB
18Accepted2/220ms13660 KiB
19Accepted3/320ms13788 KiB
20Accepted3/320ms14696 KiB
21Accepted3/321ms15476 KiB
22Accepted3/321ms15456 KiB
23Accepted3/320ms15700 KiB
24Accepted3/320ms15736 KiB