90772024-02-13 19:18:17NagyLeoLegtávolabbi leszármazottpython3Time limit exceeded 16/50312ms67860 KiB
import sys

sys.setrecursionlimit(10**9)

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/017ms11452 KiB
2Time limit exceeded0/0300ms45700 KiB
3Accepted1/117ms13100 KiB
4Accepted3/317ms13168 KiB
5Accepted3/317ms13628 KiB
6Accepted1/117ms13328 KiB
7Accepted1/117ms13860 KiB
8Accepted1/119ms14160 KiB
9Time limit exceeded0/2312ms46996 KiB
10Time limit exceeded0/3312ms47384 KiB
11Accepted3/318ms14544 KiB
12Time limit exceeded0/4301ms67804 KiB
13Runtime error0/4291ms67860 KiB
14Accepted3/346ms16392 KiB
15Runtime error0/3263ms67768 KiB
16Runtime error0/3246ms67596 KiB
17Runtime error0/3252ms67468 KiB
18Runtime error0/4200ms67460 KiB
19Runtime error0/4241ms67536 KiB
20Time limit exceeded0/4312ms67152 KiB