Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. fin = open('input.txt')
  2. n = int(fin.readline())
  3. cords = [[0 for y in range(0, n)]for x in range(0, n)]
  4.  
  5. for t in range(0, n-1):
  6.     a, b = [int(o) for o in fin.readline().split()]
  7.     y = cords[a-1]
  8.     y[b-1] = 1
  9.     x = cords[b-1]
  10.     x[a-1] = 1
  11.  
  12. maxSum = 0
  13. cityIndex = 0
  14.  
  15. for x in range(0, n - 1):
  16.     sum = 0
  17.     for y in cords[x]:
  18.         sum += y
  19.     if sum > maxSum:
  20.         cityIndex = x
  21.         maxSum = sum
  22.  
  23. fout = open('output.txt', 'w')
  24. print(maxSum, cityIndex + 1, file=fout)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement