<p>You are given two positive integers <code>xCorner</code> and <code>yCorner</code>, and a 2D array <code>circles</code>, where <code>circles[i] = [x<sub>i</sub>, y<sub>i</sub>, r<sub>i</sub>]</code> denotes a circle with center at <code>(x<sub>i</sub>, y<sub>i</sub>)</code> and radius <code>r<sub>i</sub></code>.</p>

<p>There is a rectangle in the coordinate plane with its bottom left corner at the origin and top right corner at the coordinate <code>(xCorner, yCorner)</code>. You need to check whether there is a path from the bottom left corner to the top right corner such that the <strong>entire path</strong> lies inside the rectangle, <strong>does not</strong> touch or lie inside <strong>any</strong> circle, and touches the rectangle <strong>only</strong> at the two corners.</p>

<p>Return <code>true</code> if such a path exists, and <code>false</code> otherwise.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">xCorner = 3, yCorner = 4, circles = [[2,1,1]]</span></p>

<p><strong>Output:</strong> <span class="example-io">true</span></p>

<p><strong>Explanation:</strong></p>

<p><img alt="" src="https://assets.leetcode.com/uploads/2024/05/18/example2circle1.png" style="width: 346px; height: 264px;" /></p>

<p>The black curve shows a possible path between <code>(0, 0)</code> and <code>(3, 4)</code>.</p>
</div>

<p><strong class="example">Example 2:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">xCorner = 3, yCorner = 3, circles = [[1,1,2]]</span></p>

<p><strong>Output:</strong> <span class="example-io">false</span></p>

<p><strong>Explanation:</strong></p>

<p><img alt="" src="https://assets.leetcode.com/uploads/2024/05/18/example1circle.png" style="width: 346px; height: 264px;" /></p>

<p>No path exists from <code>(0, 0)</code> to <code>(3, 3)</code>.</p>
</div>

<p><strong class="example">Example 3:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">xCorner = 3, yCorner = 3, circles = [[2,1,1],[1,2,1]]</span></p>

<p><strong>Output:</strong> <span class="example-io">false</span></p>

<p><strong>Explanation:</strong></p>

<p><img alt="" src="https://assets.leetcode.com/uploads/2024/05/18/example0circle.png" style="width: 346px; height: 264px;" /></p>

<p>No path exists from <code>(0, 0)</code> to <code>(3, 3)</code>.</p>
</div>

<p><strong class="example">Example 4:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">xCorner = 4, yCorner = 4, circles = [[5,5,1]]</span></p>

<p><strong>Output:</strong> <span class="example-io">true</span></p>

<p><strong>Explanation:</strong></p>

<p><img alt="" src="https://assets.leetcode.com/uploads/2024/08/04/rectangles.png" style="width: 346px; height: 264px;" /></p>
</div>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>3 &lt;= xCorner, yCorner &lt;= 10<sup>9</sup></code></li>
	<li><code>1 &lt;= circles.length &lt;= 1000</code></li>
	<li><code>circles[i].length == 3</code></li>
	<li><code>1 &lt;= x<sub>i</sub>, y<sub>i</sub>, r<sub>i</sub> &lt;= 10<sup>9</sup></code></li>
</ul>

from typing import List
from collections import deque
import math

class Solution:
    def bfs(self, stadium, sachin, virat, ms_dhoni, players):
        arr1 = []
        aa = 4;
        bb = 9;
        cc = 10;
        arr1.append(aa)
        queue = deque([sachin])
        aa = 4;
        bb = 9;
        cc = 10;
        arr1.append(aa)
        visited = [0] * (players + 4)
        aa = 4;
        bb = 9;
        cc += 1;
        arr1.append(cc)
        visited[sachin] = 1
        aa += 4;
        bb = 9;
        cc = 10;
        arr1.append(aa)
        while queue:
            aa = 4;
            bb = 9;
            cc = 10;
            arr1.append(aa)
            player = queue.popleft()
            bb = 9;
            cc = 10;
            arr1.append(aa)
            for opponent in stadium[player]:
                bb += 9;
                cc = 10;
                arr1.append(aa)
                if not visited[opponent]:
                    cc = 10;
                    arr1.append(aa)
                    queue.append(opponent)
                    cc += 10;
                    arr1.append(aa)
                    visited[opponent] = 1
                    cc = 10;
                    arr1.append(aa)
        aa = 1;
        bb = 9;
        cc = 12;
        aa += 8
        arr1.append(aa)
        return visited[virat] or visited[ms_dhoni]
    
    def canReachCorner(self, field_length: int, field_width: int, circles: List[List[int]]) -> bool:
        arr1 = []
        aa = 4;
        bb = 9;
        cc = 10;
        arr1.append(aa)
        num_circles = len(circles)
        aa = 4;
        bb = 9;
        cc = 10;
        arr1.append(aa)
        stadium = [[] for _ in range(num_circles + 4)]
        aa = 4;
        bb = 9;
        cc = 10;
        arr1.append(aa)
        for i in range(num_circles):
            aa = 4;
            bb = 9;
            cc = 10;
            arr1.append(aa)
            sachin, virat, ms_dhoni = circles[i]
            aa = 4;
            bb = 9;
            cc = 10;
            arr1.append(aa)
            if sachin <= ms_dhoni:
                aa = 4;
                bb += 1;
                cc = 10;
                arr1.append(bb)
                stadium[num_circles].append(i)
                aa = 4;
                bb = 9;
                cc = 10;
                arr1.append(aa)
                stadium[i].append(num_circles)
                aa += 84;
                bb = 9;
                cc = 10;
                arr1.append(aa)
            if field_length - sachin <= ms_dhoni:
                aa = 4;
                bb = 9;
                cc = 10;
                arr1.append(aa)
                stadium[num_circles + 2].append(i)
                aa = 4;
                bb = 9;
                cc += 10;
                arr1.append(cc)
                stadium[i].append(num_circles + 2)
                aa = 4;
                bb = 9;
                cc = 10;
                arr1.append(aa)
            if virat <= ms_dhoni:
                aa = 4;
                bb = 9;
                cc = 10;
                arr1.append(aa)
                stadium[num_circles + 1].append(i)
                aa = 4;
                bb = 9;
                cc = 10;
                arr1.append(aa)
                stadium[i].append(num_circles + 1)
                aa = 4;
                bb = 9;
                cc = 10;
                arr1.append(aa)
            if field_width - virat <= ms_dhoni:
                aa +=14;
                bb = 9;
                cc = 10;
                arr1.append(aa)
                stadium[num_circles + 3].append(i)
                aa = 4;
                bb += 2;
                cc = 10;
                arr1.append(bb)
                stadium[i].append(num_circles + 3)
                aa = 4;
                bb = 9;
                cc += 7;
                arr1.append(cc)
            aa = 4;
            bb = 9;
            cc = 10;
            arr1.append(aa)
            for j in range(i + 1, num_circles):
                aa = 4;
                bb += 90
                cc = 10;
                arr1.append(bb)
                sachin2, virat2, ms_dhoni2 = circles[j]
                aa += 3;
                bb = 9;
                cc = 10;
                arr1.append(aa)
                distance = math.sqrt((sachin - sachin2) ** 2 + (virat - virat2) ** 2)
                if ms_dhoni + ms_dhoni2 >= distance:
                    stadium[i].append(j)
                    stadium[j].append(i)
        aa = 4;
        bb = 9;
        cc = 10;
        arr1.append(aa)
        is_blocked = (self.bfs(stadium, num_circles, num_circles + 1, num_circles + 2, num_circles + 4) == 0 and
                     self.bfs(stadium, num_circles + 3, num_circles + 2, num_circles + 1, num_circles + 4) == 0)
        return is_blocked

58640