90762024-02-13 19:17:24NagyLeoLegtávolabbi leszármazottpython3Time limit exceeded 16/50321ms67740 KiB
import sys

sys.setrecursionlimit(10**6)

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/017ms11380 KiB
2Accepted0/0291ms45584 KiB
3Accepted1/117ms12860 KiB
4Accepted3/317ms12884 KiB
5Accepted3/317ms13160 KiB
6Accepted1/117ms13324 KiB
7Accepted1/117ms13396 KiB
8Accepted1/119ms14044 KiB
9Time limit exceeded0/2310ms46728 KiB
10Time limit exceeded0/3321ms47480 KiB
11Accepted3/319ms14592 KiB
12Runtime error0/4287ms67740 KiB
13Runtime error0/4291ms67660 KiB
14Accepted3/346ms16776 KiB
15Runtime error0/3266ms66868 KiB
16Runtime error0/3254ms66872 KiB
17Runtime error0/3254ms66892 KiB
18Runtime error0/4211ms66644 KiB
19Runtime error0/4254ms66688 KiB
20Time limit exceeded0/4305ms66352 KiB