SHARE
TWEET

Untitled

a guest Oct 20th, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. def f(lst):
  3.     nums = {}
  4.     n, nm = None, 0
  5.     for i in lst:
  6.         nums[i] = t = nums.get(i, 0) + 1
  7.         if t > nm:
  8.             n, nm = i, t
  9.     return n
  10.  
  11.  
  12. N = int(input())
  13. roads = []
  14. if N == 1:
  15.     print(0, 0)
  16.     quit()
  17. for i in range(N - 1):
  18.     roads.append(input().split())
  19.  
  20. # val = list(itertools.chain.from_iterable(roads))
  21. val = [j for sub in roads for j in sub]
  22. city = f(val)
  23. count = 0
  24. for i in range(N - 1):
  25.     for g in range(2):
  26.         if int(roads[i][g]) == int(city):
  27.             count += 1  # TODO rewrite
  28.  
  29. a = 1
  30. c = N - 1 - count
  31. if c == 0:
  32.     print(count, city)
  33.     quit()
  34. else:
  35.     for i in range(c):
  36.         count += (a + 1) ** 2
  37.         a += 1
  38. print(count, city)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top