title: How to decrease the time taken for this question's code?
body: <blockquote>
  <p>Given n points A[1..n] in the 2-D plane, where i-th point has two attributes A[i].x and A[i].y representing x-coordinate and y-coordinate. Find 3 points A[i], A[j], A[k] (i, j, k are distinct) such that distance(A[i], A[j]) + distance(A[j], A[k]) + distance(A[k], A[i]) is minimized. Here distance(A[i], A[j]) means the Euclid Distance, which is equals to sqrt( (A[i].x - A[j].x)^2 + (A[i].y - A[j].y)^2). You need to output the minimum possible distance.</p>
  <p>Input: The first line contains an integer T indicating the number of test cases.</p>
  <p>Each test case starts with a positive integer n indicating the number of points.</p>
  <p>The following n lines contain two real numbers A[i].x and A[i].y with at-most 6 digits after decimal point describing the coordinates of the point.</p>
  <p>Output: T lines in total. Each line starts with &quot;Case #: &quot; and followed by minimum length. Here &quot;#&quot; is the number of the test case starting from 1.</p>
  <p>Answers within an absolute or relative error of 10^-6 will be accepted.</p>
  <p>Constraints:</p>
  <ul>
  <li>1 ≤ T ≤ 10</li>
  <li>3 ≤ n ≤ 100000</li>
  <li>0 ≤ A[i].x, A[i].y ≤ 10000</li>
  <li>A[i].x, A[i].y are real numbers with atmost 6 digits after decimal position.</li>
  </ul>
  </blockquote>
  <p>Example Input:</p>
  <pre><code>1
  4
  0.0 0.0
  2.0 2.0
  2.0 0.0
  1.0 1.0
  </code></pre>
  <p>Example Output:</p>
  <pre><code>Case 1: 4.8284271247
  </code></pre>
  <p>Explanation
  One possible solution is to select these 3 points (0, 0), (2, 0), (1, 1), the length is sqrt(2) + sqrt(2) + 2</p>
  <pre><code>from math import sqrt as s
  
  class Point():
     def __init__(self,x,y):
        self.x = x
        self.y = y
  
  
  def bruteforce(p):
      d = []
      q=len(p)
      for i in range(q):
          j=i+1
          while j&lt;q:
              temp = s((p[j].x - p[i].x) * (p[j].x - p[i].x) + (p[j].y - p[i].y) * (p[j].y - p[i].y))
              d.append(temp)
      d.sort()
      return (d[0]+d[1]+d[2])
  
  def solution():
    t = int(input())
    for i in range(t):
       temp = 0
       n = int(input())
       p = []
       for j in range(n):
          a, b = map(float, input().split())
          temp = Point(a, b)
          p.append(temp)
    return(bruteforce(p))
  
  print(solution())
  </code></pre>
  <p>What shall I do to decrease the time complexity? Anyone please help me!</p>