90782024-02-13 19:18:53NagyLeoLegtávolabbi leszármazottpython3Time limit exceeded 16/50312ms67568 KiB
import sys

sys.setrecursionlimit(10**5)

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/017ms11468 KiB
2Time limit exceeded0/0303ms45536 KiB
3Accepted1/117ms12956 KiB
4Accepted3/317ms13124 KiB
5Accepted3/317ms13216 KiB
6Accepted1/117ms13260 KiB
7Accepted1/117ms13468 KiB
8Accepted1/119ms14352 KiB
9Time limit exceeded0/2312ms47548 KiB
10Time limit exceeded0/3303ms47740 KiB
11Accepted3/318ms14568 KiB
12Runtime error0/4296ms67540 KiB
13Runtime error0/4291ms67568 KiB
14Accepted3/346ms16748 KiB
15Runtime error0/3280ms67300 KiB
16Runtime error0/3261ms67300 KiB
17Runtime error0/3277ms67332 KiB
18Runtime error0/4202ms67392 KiB
19Runtime error0/4241ms67344 KiB
20Runtime error0/4293ms67404 KiB