Problem p02805 (python)

Fixed submission:
import sys
input = sys.stdin.readline
import math

def gai(x1,y1,x2,y2,x3,y3):
    #coordinates

    #length of each side squared and area of the triangle
    a2 = (x2 - x3) **2 + (y2 -y3) ** 2
    b2 = (x1 - x3) **2 + (y1 -y3) ** 2
    c2 = (x2 - x1) **2 + (y2 -y1) ** 2
    area = ((x2 - x1) * (y3 -y1) - (x3 -x1) * (y2- y1)) / 2

    #is_triangle
    if area == 0:
        xmax=max(x1,x2,x3)
        xmin=min(x1,x2,x3)
        x=xmax-xmin
        ymax=max(y1,y2,y3)
        ymin=min(y1,y2,y3)
        y=ymax-ymin
        r=(x*x+y*y)**0.5/2
        gx=(xmax+xmin)/2
        gy=(ymax+ymin)/2
        return gx,gy,r

    #circumcenter coordinate and radius
    x = (a2*(b2+c2-a2)*x1 + b2*(c2+a2-b2)*x2 + c2*(a2+b2-c2)*x3) / (16*area*area)
    y = (a2*(b2+c2-a2)*y1 + b2*(c2+a2-b2)*y2 + c2*(a2+b2-c2)*y3) / (16*area*area)
    r = ((x1-x)**2 + (y1-y)**2)**0.5

    #rounding
    #return the equation
    return x, y, r

def gai2(x1,y1,x2,y2):
    return (x1+x2)/2,(y1+y2)/2,((x1-x2)**2+(y1-y2)**2)**0.5/2

N=int(input())
X=[]
Y=[]
for i in range(N):
    x,y=map(int,input().split())
    X.append(x)
    Y.append(y)
if N==2:
    print(((X[1]-X[0])**2+(Y[1]-Y[0])**2)**0.5/2)
    exit()
#print(X,Y)
dm=float("inf")
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            """gx=(X[i]+X[j]+X[k])/3
            gy=(Y[i]+Y[j]+Y[k])/3
            han=((gx-X[i])**2+(gy-Y[i])**2)"""
            gx,gy,r=gai(X[i],Y[i],X[j],Y[j],X[k],Y[k])
            #print(i,j,k)
            if dm>r:
                flg=True
                for l in range(N):
                    if l==i or l==j or l==k:
                        continue
                    if ((X[l]-gx)**2+(Y[l]-gy)**2)>r**2:
                        flg=False
                if flg:
                    dm=r
for i in range(N-1):
    for j in range(N):
        gx,gy,r=gai2(X[i],Y[i],X[j],Y[j])
        #print(i,j,k)
        if dm>r:
            flg=True
            for l in range(N):
                if l==i or l==j:
                    continue
                if ((X[l]-gx)**2+(Y[l]-gy)**2)>r**2:
                    flg=False
            if flg:
                dm=r
print(dm)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import math

def gai(x1,y1,x2,y2,x3,y3):
    #coordinates

    #length of each side squared and area of the triangle
    a2 = (x2 - x3) **2 + (y2 -y3) ** 2
    b2 = (x1 - x3) **2 + (y1 -y3) ** 2
    c2 = (x2 - x1) **2 + (y2 -y1) ** 2
    area = ((x2 - x1) * (y3 -y1) - (x3 -x1) * (y2- y1)) / 2

    #is_triangle
    if area == 0:
        return "three points exist on the same line"

    #circumcenter coordinate and radius
    x = (a2*(b2+c2-a2)*x1 + b2*(c2+a2-b2)*x2 + c2*(a2+b2-c2)*x3) / (16*area*area)
    y = (a2*(b2+c2-a2)*y1 + b2*(c2+a2-b2)*y2 + c2*(a2+b2-c2)*y3) / (16*area*area)
    r = ((x1-x)**2 + (y1-y)**2)**0.5

    #rounding
    #return the equation
    return x, y, r

N=int(input())
X=[]
Y=[]
for i in range(N):
    x,y=map(int,input().split())
    X.append(x)
    Y.append(y)
if N==2:
    print(((X[1]-X[0])**2+(Y[1]-Y[0])**2)**0.5/2)
    exit()
#print(X,Y)
dm=float("inf")
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            """gx=(X[i]+X[j]+X[k])/3
            gy=(Y[i]+Y[j]+Y[k])/3
            han=((gx-X[i])**2+(gy-Y[i])**2)"""
            gx,gy,r=gai(X[i],Y[i],X[j],Y[j],X[k],Y[k])
            #print(i,j,k)
            if dm>r:
                flg=True
                for l in range(N):
                    if l==i or l==j or l==k:
                        continue
                    if ((X[l]-gx)**2+(Y[l]-gy)**2)>r**2:
                        flg=False
                if flg:
                    dm=r
print(dm)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import math

def gai(x1,y1,x2,y2,x3,y3):
    #coordinates

    #length of each side squared and area of the triangle
    a2 = (x2 - x3) **2 + (y2 -y3) ** 2
    b2 = (x1 - x3) **2 + (y1 -y3) ** 2
    c2 = (x2 - x1) **2 + (y2 -y1) ** 2
    area = ((x2 - x1) * (y3 -y1) - (x3 -x1) * (y2- y1)) / 2

    #is_triangle
    if area == 0:
        return "three points exist on the same line"

    #circumcenter coordinate and radius
    x = (a2*(b2+c2-a2)*x1 + b2*(c2+a2-b2)*x2 + c2*(a2+b2-c2)*x3) / (16*area*area)
    y = (a2*(b2+c2-a2)*y1 + b2*(c2+a2-b2)*y2 + c2*(a2+b2-c2)*y3) / (16*area*area)
    r = ((x1-x)**2 + (y1-y)**2)**0.5

    #rounding
    #return the equation
    return x, y, r

N=int(input())
X=[]
Y=[]
for i in range(N):
    x,y=map(int,input().split())
    X.append(x)
    Y.append(y)
if N==2:
    print(((X[1]-X[0])**2+(Y[1]-Y[0])**2)**0.5)
#print(X,Y)
dm=float("inf")
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            """gx=(X[i]+X[j]+X[k])/3
            gy=(Y[i]+Y[j]+Y[k])/3
            han=((gx-X[i])**2+(gy-Y[i])**2)"""
            gx,gy,r=gai(X[i],Y[i],X[j],Y[j],X[k],Y[k])
            print(i,j,k)
            if dm>r:
                flg=True
                for l in range(N):
                    if l==i orimport sys
input = sys.stdin.readline
import math

def gai(x1,y1,x2,y2,x3,y3):
    #coordinates

    #length of each side squared and area of the triangle
    a2 = (x2 - x3) **2 + (y2 -y3) ** 2
    b2 = (x1 - x3) **2 + (y1 -y3) ** 2
    c2 = (x2 - x1) **2 + (y2 -y1) ** 2
    area = ((x2 - x1) * (y3 -y1) - (x3 -x1) * (y2- y1)) / 2

    #is_triangle
    if area == 0:
        return "three points exist on the same line"

    #circumcenter coordinate and radius
    x = (a2*(b2+c2-a2)*x1 + b2*(c2+a2-b2)*x2 + c2*(a2+b2-c2)*x3) / (16*area*area)
    y = (a2*(b2+c2-a2)*y1 + b2*(c2+a2-b2)*y2 + c2*(a2+b2-c2)*y3) / (16*area*area)
    r = ((x1-x)**2 + (y1-y)**2)**0.5

    #rounding
    #return the equation
    return x, y, r

N=int(input())
X=[]
Y=[]
for i in range(N):
    x,y=map(int,input().split())
    X.append(x)
    Y.append(y)
if N==2:
    print(((X[1]-X[0])**2+(Y[1]-Y[0])**2)**0.5)
    exit()
#print(X,Y)
dm=float("inf")
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            """gx=(X[i]+X[j]+X[k])/3
            gy=(Y[i]+Y[j]+Y[k])/3
            han=((gx-X[i])**2+(gy-Y[i])**2)"""
            gx,gy,r=gai(X[i],Y[i],X[j],Y[j],X[k],Y[k])
            print(i,j,k)
            if dm>r:
                flg=True
                for l in range(N):
                    if l==i or l==j or l==k:
                        continue
                    if ((X[l]-gx)**2+(Y[l]-gy)**2)>r**2:
                        flg=False
                if flg:
                    dm=r
print(dm)
 l==j or l==k:
                        continue
                    if ((X[l]-gx)**2+(Y[l]-gy)**2)>r**2:
                        flg=False
                if flg:
                    dm=r
print(dm)