94392024-02-21 17:46:06NagyLeoKaktuszgráfpython3Runtime error 38/5024ms16768 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
base38/50
1Accepted0/018ms11016 KiB
2Accepted0/019ms11964 KiB
3Accepted2/219ms12252 KiB
4Accepted2/219ms12956 KiB
5Accepted2/219ms13116 KiB
6Accepted2/220ms13244 KiB
7Accepted2/221ms13856 KiB
8Accepted2/221ms13412 KiB
9Accepted2/220ms13460 KiB
10Accepted2/221ms13692 KiB
11Accepted2/221ms13604 KiB
12Accepted2/221ms13816 KiB
13Accepted2/220ms14208 KiB
14Accepted2/221ms14072 KiB
15Accepted2/221ms14324 KiB
16Accepted2/221ms14340 KiB
17Accepted2/221ms14376 KiB
18Accepted2/220ms14716 KiB
19Accepted3/321ms14684 KiB
20Accepted3/323ms16412 KiB
21Runtime error0/324ms16768 KiB
22Runtime error0/323ms16564 KiB
23Runtime error0/324ms16512 KiB
24Runtime error0/323ms16608 KiB