90802024-02-13 19:19:49NagyLeoLegtávolabbi leszármazottpython3Time limit exceeded 16/50314ms67404 KiB
import sys

sys.setrecursionlimit(10**6)

deepest = 0
furt = 0

def main():
  global deepest, furt
  n = int(input())
  connections={} # graph
  con = set() # fiuk

  for i in range(n-1):
    a,b=map(int,input().split())
    try:
      connections[a].append(b)
    except:
      connections[a] = [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):
    global deepest, furt
    if deepest < depth:
        deepest = depth
        furt = node
    try:
      for i in connections[node]:
        deepsearch(i, depth+1)
    except:
      return

  deepsearch(parent, 0)
  print(furt)

main()
SubtaskSumTestVerdictTimeMemory
base16/50
1Accepted0/017ms11332 KiB
2Accepted0/0284ms45524 KiB
3Accepted1/118ms12832 KiB
4Accepted3/317ms12904 KiB
5Accepted3/318ms13188 KiB
6Accepted1/117ms13400 KiB
7Accepted1/117ms13356 KiB
8Accepted1/119ms14136 KiB
9Time limit exceeded0/2314ms47440 KiB
10Time limit exceeded0/3305ms47836 KiB
11Accepted3/318ms14712 KiB
12Runtime error0/4291ms67404 KiB
13Runtime error0/4289ms67020 KiB
14Accepted3/346ms16924 KiB
15Runtime error0/3282ms66696 KiB
16Runtime error0/3243ms66736 KiB
17Runtime error0/3259ms66676 KiB
18Runtime error0/4202ms66692 KiB
19Runtime error0/4239ms66700 KiB
20Time limit exceeded0/4307ms66444 KiB