94402024-02-21 17:46:39NagyLeoKaktuszgráfpypy3Accepted 50/5082ms95260 KiB
from sys import stdin, stdout
input=stdin.readline

def main():
    N, M = map(int, input().split())
    graph = {}

    for i in range(M):
        A, B = map(int, input().split())
        try:
            graph[A].add(B)
        except:
            graph[A] = {B}
        try:
            graph[B].add(A)
        except:
            graph[B] = {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/043ms76688 KiB
2Accepted0/061ms86208 KiB
3Accepted2/257ms85400 KiB
4Accepted2/261ms86640 KiB
5Accepted2/267ms86456 KiB
6Accepted2/271ms91112 KiB
7Accepted2/257ms89240 KiB
8Accepted2/259ms89100 KiB
9Accepted2/270ms89792 KiB
10Accepted2/274ms90412 KiB
11Accepted2/275ms90332 KiB
12Accepted2/270ms90416 KiB
13Accepted2/278ms95260 KiB
14Accepted2/270ms90660 KiB
15Accepted2/282ms93596 KiB
16Accepted2/272ms91144 KiB
17Accepted2/271ms90428 KiB
18Accepted2/267ms91172 KiB
19Accepted3/378ms91712 KiB
20Accepted3/359ms91528 KiB
21Accepted3/363ms90548 KiB
22Accepted3/357ms90212 KiB
23Accepted3/354ms90768 KiB
24Accepted3/354ms90660 KiB