90822024-02-13 19:27:12NagyLeoLegtávolabbi leszármazottpypy3Runtime error 16/50125ms104316 KiB
import sys

sys.setrecursionlimit(10**6)

deepest = 0
furt = 0

def main2():
  global deepest, furt
  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):
    global deepest, furt
    if deepest < depth:
        deepest = depth
        furt = node
    for i in connections[node]:
        deepsearch(i, depth+1)

  deepsearch(parent, 0)
  print(furt)


main2()
SubtaskSumTestVerdictTimeMemory
base16/50
1Accepted0/041ms77644 KiB
2Runtime error0/0125ms104316 KiB
3Accepted1/141ms78220 KiB
4Accepted3/339ms78272 KiB
5Accepted3/341ms78356 KiB
6Accepted1/141ms78960 KiB
7Accepted1/146ms82440 KiB
8Accepted1/165ms87912 KiB
9Runtime error0/2111ms102780 KiB
10Runtime error0/3114ms102864 KiB
11Accepted3/354ms82936 KiB
12Runtime error0/4112ms102860 KiB
13Runtime error0/4112ms102504 KiB
14Accepted3/3119ms97928 KiB
15Runtime error0/3112ms102596 KiB
16Runtime error0/3109ms102276 KiB
17Runtime error0/3112ms102576 KiB
18Runtime error0/4115ms102548 KiB
19Runtime error0/4116ms102280 KiB
20Runtime error0/4108ms102252 KiB