90832024-02-13 19:35:05NagyLeoLegtávolabbi leszármazottpython3Time limit exceeded 16/50324ms67600 KiB
import sys

sys.setrecursionlimit(10**6)

def main2():
  n = int(input())
  connections=[[] for i in range(n+1)] # graph
  con = set() # fiuk

  for i in range(n-1):
    a,b=map(int,input().split())
    connections[a].append(b)
    con.add(b)

  parent = 0
  for f in range(1,n+1):
    if f not in con:
      parent = f
      break

  def deepsearch(node, depth, result, name):
    if result < depth:
        result = depth
        name=node
    for i in connections[node]:
        result,name=deepsearch(i, depth+1, result, name)
    return (result,name)

  print(deepsearch(parent, 0, 0, 0)[1])


main2()
SubtaskSumTestVerdictTimeMemory
base16/50
1Accepted0/017ms11428 KiB
2Accepted0/0279ms45516 KiB
3Accepted1/117ms12660 KiB
4Accepted3/318ms12752 KiB
5Accepted3/317ms13076 KiB
6Accepted1/117ms12972 KiB
7Accepted1/117ms13392 KiB
8Accepted1/119ms13776 KiB
9Time limit exceeded0/2324ms47836 KiB
10Time limit exceeded0/3310ms47928 KiB
11Accepted3/319ms14260 KiB
12Runtime error0/4273ms67600 KiB
13Runtime error0/4275ms67312 KiB
14Accepted3/346ms16892 KiB
15Runtime error0/3245ms67132 KiB
16Runtime error0/3239ms66908 KiB
17Runtime error0/3256ms66948 KiB
18Runtime error0/4207ms66832 KiB
19Runtime error0/4248ms66900 KiB
20Runtime error0/4272ms66708 KiB