90792024-02-13 19:19:14NagyLeoLegtávolabbi leszármazottpypy3Runtime error 16/50141ms104264 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/043ms77528 KiB
2Runtime error0/0141ms104264 KiB
3Accepted1/143ms77948 KiB
4Accepted3/339ms78472 KiB
5Accepted3/341ms79340 KiB
6Accepted1/148ms79376 KiB
7Accepted1/152ms83308 KiB
8Accepted1/171ms88624 KiB
9Runtime error0/2123ms102508 KiB
10Runtime error0/3123ms102588 KiB
11Accepted3/354ms83800 KiB
12Runtime error0/4115ms102308 KiB
13Runtime error0/4116ms101944 KiB
14Accepted3/3129ms99916 KiB
15Runtime error0/3114ms101736 KiB
16Runtime error0/3115ms101728 KiB
17Runtime error0/3123ms101452 KiB
18Runtime error0/4115ms101300 KiB
19Runtime error0/4111ms101384 KiB
20Runtime error0/4112ms101320 KiB