Problem p02764 (python)

Fixed submission:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    # 2円の中心間の距離の2乗
    def D2(x1,y1,x2,y2):
        return (x1-x2)**2+(y1-y2)**2

    # 2円が交点を持つか
    def check(R1,R2):
        x1,y1,r1 = R1
        x2,y2,r2 = R2
        d2 = D2(x1,y1,x2,y2)
        if (r1-r2)**2 < d2 <= (r1+r2)**2:
            return 1
        else:
            return 0

    # 2円の交点を出力
    def point(R1,R2):
        if not check(R1,R2):
            return []
        else:
            x1,y1,r1 = R1
            x2,y2,r2 = R2
            x2 -= x1
            y2 -= y1
            r = x2**2+y2**2
            a = (r+r1**2-r2**2)/2
            d = (r*r1**2-a**2)**0.5
            X,Y = a*x2/r, a*y2/r
            k = d/r
            X1,Y1 = X+y2*k+x1, Y-x2*k+y1
            X2,Y2 = X-y2*k+x1, Y+x2*k+y1
            return [(X1,Y1),(X2,Y2)]

    # 円に点が入っているか
    def inR(p,R):
        x2,y2 = p
        x1,y1,r1 = R
        d2 = D2(x1,y1,x2,y2)
        if d2 <= r1**2+1e-3:
            return 1
        else:
            return 0

    n,k = LI()
    p = LIR(n)
    l = 0
    r = 1000000
    while r-l > 1e-6:
        t = (l+r) / 2
        P = []
        for i in range(n):
            xi,yi,ci = p[i]
            ri = t/ci
            P.append((xi,yi))
            for j in range(i):
                xj,yj,cj = p[j]
                rj = t/cj
                ps = point((xi,yi,ri),(xj,yj,rj))
                for pi in ps:
                    P.append(pi)
        for pi in P:
            s = 0
            for x,y,c in p:
                r1 = t/c
                if inR(pi,(x,y,r1)):
                    s += 1
                if s >= k:
                    break
            if s >= k:
                r = t
                break
        else:
            l = t
    print(l)
    return

#Solve
if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def d(i,j):
        return ((p[i][0]-p[j][0])**2+(p[i][1]-p[j][1])**2)**0.5

    def check(i,j,t):
        ri = t/p[i][2]
        rj = t/p[j][2]
        dij = d(i,j)
        if dij <= ri+rj or dij <= abs(ri-rj):
            return 1
        else:
            return 0

    def bit_count(n):
          return bin(n).count("1")

    def MaximumIndependentSet(n,v):
        mid = n>>1
        k = mid
        l = 1<<k
        f = [1]*l #sが独立集合であるかどうか (i < mid)
        for i in range(mid):
          for j in range(i+1,mid):
              if v[i][j]:
                  f[(1<<i)|(1<<j)] = 0
        for s in range(l):
          if not f[s]:
              for i in range(k):
                  ns = s|(1<<i)
                  f[ns] = 0

        dp = [bit_count(s) if f[s] else 0 for s in range(l)] #独立集合の要素数 (i < mid)

        k_ = n-mid
        l_ = 1<<k_
        f_ = [1]*l_ #sが独立集合であるかどうか (i >= mid)
        for i in range(mid,n):
          x = i-mid
          for j in range(i+1,n):
              if v[i][j]:
                  y = j-mid
                  f_[(1<<x)|(1<<y)] = 0
        for s in range(l_):
          if not f_[s]:
              for i in range(k_):
                  ns = s|(1<<i)
                  f_[ns] = 0

        dp_ = [bit_count(s) if f_[s] else 0 for s in range(l_)] #部分集合の独立集合の要素数の最大値 (i >= mid)
        for s in range(l_):
          for i in range(k_):
              ns = s|(1<<i)
              if dp_[ns] < dp_[s]:
                  dp_[ns] = dp_[s]

        se = [l_-1]*l #sの頂点と辺で結ばれていない要素数最大の集合U
        for i in range(k):
          s = 1<<i
          for j in range(mid,n):
              if v[i][j]:
                  se[s] ^= (1<<(j-mid))
        for s in range(l):
          for i in range(k):
              bi = 1<<i
              if s&bi:continue
              se[s|bi] = se[s]&se[bi]

        res = 0
        for s in range(l):
          res = max(res, dp[s]+dp_[se[s]])
        return res

    n,k = LI()
    p = LIR(n)
    l = 0
    r = 1000000
    while r-l > 1e-7:
        t = (l+r) / 2
        v = [[1]*n for i in range(n)]
        for i in range(n):
          v[i][i] = 0
        for i in range(n):
            for j in range(n):
                if i == j:
                    continue
                if check(i,j,t):
                    v[i][j] = v[j][i] = 0
        if MaximumIndependentSet(n,v) >= k:
            r = t
        else:
            l = t
    print(l)
    return

#Solve
if __name__ == "__main__":
    solve()