90812024-02-13 19:24:46NagyLeoLegtávolabbi leszármazottpython3Runtime error 21/50293ms67724 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
base21/50
1Accepted0/017ms11168 KiB
2Accepted0/0273ms45452 KiB
3Accepted1/117ms12572 KiB
4Accepted3/317ms12936 KiB
5Accepted3/317ms12972 KiB
6Accepted1/117ms13212 KiB
7Accepted1/117ms13404 KiB
8Accepted1/120ms14160 KiB
9Accepted2/2293ms48236 KiB
10Accepted3/3287ms48136 KiB
11Accepted3/318ms14688 KiB
12Runtime error0/4261ms67724 KiB
13Runtime error0/4272ms67564 KiB
14Accepted3/343ms16704 KiB
15Runtime error0/3237ms67376 KiB
16Runtime error0/3248ms67332 KiB
17Runtime error0/3256ms67116 KiB
18Runtime error0/4207ms66900 KiB
19Runtime error0/4264ms66800 KiB
20Runtime error0/4273ms66780 KiB