Problem p02805 (python)

Fixed submission:
def dist(i,j):
    return hypot(xy[i][0]-xy[j][0],xy[i][1]-xy[j][1])
    
def center(i,j,k):
    a,b = xy[i]
    c,d = xy[j]
    e,f = xy[k]
    
    #一直線上？
    pp = (e-a)*(b-d)-(c-a)*(b-f)
    if pp == 0:
        if (c-a) == 0:
            ratio = (f-b)/(d-b) 
            if ratio > 1: #(a,b),(c,d),(e,f)の順番
                return (e+a)/2,(f+b)/2
            elif ratio > 0: #(a,b),(e,f),(c,d)の順番
                return (c+a)/2,(d+b)/2
            else: #(e,f),(a,b),(c,d)の順番
                return (c+e)/2,(d+f)/2
        else:
            ratio = (e-a)/(c-a) 
            if ratio > 1: #(a,b),(c,d),(e,f)の順番
                return (e+a)/2,(f+b)/2
            elif ratio > 0: #(a,b),(e,f),(c,d)の順番
                return (c+a)/2,(d+b)/2
            else: #(e,f),(a,b),(c,d)の順番
                return (c+e)/2,(d+f)/2

    bunbo = 2*(a*(d-f)+c*(f-b)+e*(b-d))
    px = (a*a+b*b)*(d-f)+(c*c+d*d)*(f-b)+(e*e+f*f)*(b-d)
    px /= bunbo
    py = (a*a+b*b)*(e-c)+(c*c+d*d)*(a-e)+(e*e+f*f)*(c-a)
    py /= bunbo
    return px,py
    
###########################################################################
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read

n = int(input())
#n,k = [int(i) for i in readline().split()]
#a = [int(i) for i in readline().split()]

xy = [[int(i) for i in readline().split()] for _ in range(n)]
xy += [[0,0]]
from math import hypot
if n==2:
    print(dist(0,1)/2)
    exit()


from itertools import combinations
L = list(range(n))

ans = 1000000000
for i,j,k in combinations(L,3):
    xy[-1] = center(i,j,k)
    d = max(dist(l,-1) for l in range(n))
    if ans > d:
        ans = d


for i,j in combinations(L,2):
    xx = (xy[i][0]+xy[j][0])/2
    yy = (xy[i][1]+xy[j][1])/2
    xy[-1] = [xx,yy]
    d = max(dist(l,-1) for l in range(n))
    if ans > d:
        ans = d

print(ans)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read

n = int(input())
#n,k = [int(i) for i in readline().split()]
#a = [int(i) for i in readline().split()]

xy = [[int(i) for i in readline().split()] for _ in range(n)]
xy += [[0,0]]
from math import hypot
if n==2:
    print(dist(0,1)/2)
    exit()

def dist(i,j):
    return hypot(xy[i][0]-xy[j][0],xy[i][1]-xy[j][1])
    
def center(i,j,k):
    a,b = xy[i]
    c,d = xy[j]
    e,f = xy[k]
    
    #一直線上？
    pp = (e-a)*(b-d)-(c-a)*(b-f)
    if pp == 0:
        if (c-a) == 0:
            ratio = (f-b)/(d-b) 
            if ratio > 1: #(a,b),(c,d),(e,f)の順番
                return (e+a)/2,(f+b)/2
            elif ratio > 0: #(a,b),(e,f),(c,d)の順番
                return (c+a)/2,(d+b)/2
            else: #(e,f),(a,b),(c,d)の順番
                return (c+e)/2,(d+f)/2
        else:
            ratio = (e-a)/(c-a) 
            if ratio > 1: #(a,b),(c,d),(e,f)の順番
                return (e+a)/2,(f+b)/2
            elif ratio > 0: #(a,b),(e,f),(c,d)の順番
                return (c+a)/2,(d+b)/2
            else: #(e,f),(a,b),(c,d)の順番
                return (c+e)/2,(d+f)/2


    py = (e-a)*(a*a+b*b-c*c-d*d)-(c-a)*(a*a+b*b-e*e-f*f)
    py /= 2*pp
    
    if c == a:
        px = 2*(b-f)*py-a*a-b*b+e*e+f*f
        px /= 2*(e-a)
    else:
        px = 2*(b-d)*py-a*a-b*b+c*c+d*d
        px /= 2*(c-a)
    
    return px,py   

from itertools import combinations
L = list(range(n))

ans = 10000000
for i,j,k in combinations(L,3):
    xy[-1] = center(i,j,k)
    d = max(dist(l,-1) for l in range(n))
    if ans > d:
        ans = d

print(ans)