Submission #42043422


Source Code Expand

# dijkstra
import heapq
########################################
class dijkstra():
    INF = float("inf")
    def __init__(self, numV):
        self.numV = numV
        self.e = [[] for _ in range(numV)]
    def makeEdge(self, s, t, cost):
        self.e[s].append((t, cost))
        self.e[t].append((s, cost))
    def solve(self, nodeS):
        self.cost = [self.INF] * self.numV # cost
        self.parent = [-1] * self.numV # parent node
        q = [(0, nodeS)]  # 初期ノード(cost 0)
        self.cost[nodeS] = 0
        heapq.heapify(q)
        while len(q) > 0:
            curcost, curnode = heapq.heappop(q)
            if curcost > self.cost[curnode]:
                continue
            for nextnode, edgecost in self.e[curnode]:
                nextcost = curcost + edgecost
                if self.cost[nextnode] > nextcost:
                    self.cost[nextnode] = nextcost
                    self.parent[nextnode] = curnode
                    heapq.heappush(q, (nextcost, nextnode))
########################################
n, d = map(int, input().split())
dat = []
for _ in range(n): dat.append(tuple(map(int, input().split())))
dj = dijkstra(n)
for i in range(n):
    x1, y1 = dat[i]
    for j in range(i+1, n):
        x2, y2 = dat[j]
        if (x1-x2)**2 + (y1-y2)**2 <= (d**2):
            dj.makeEdge(i, j, 1)
cost = dj.solve(0)
for i in range(n): print("Yes" if dj.cost[i] != dj.INF else "No")

Submission Info

Submission Time
Task C - Virus
User recuraki
Language PyPy3 (7.3.0)
Score 300
Code Size 1465 Byte
Status AC
Exec Time 536 ms
Memory 261976 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 38
Set Name Test Cases
Sample sample00.txt, sample01.txt, sample02.txt
All sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt, testcase27.txt, testcase28.txt, testcase29.txt, testcase30.txt, testcase31.txt, testcase32.txt, testcase33.txt, testcase34.txt
Case Name Status Exec Time Memory
sample00.txt AC 63 ms 62592 KiB
sample01.txt AC 49 ms 62720 KiB
sample02.txt AC 50 ms 62640 KiB
testcase00.txt AC 47 ms 62668 KiB
testcase01.txt AC 116 ms 74824 KiB
testcase02.txt AC 130 ms 75508 KiB
testcase03.txt AC 125 ms 74924 KiB
testcase04.txt AC 140 ms 75532 KiB
testcase05.txt AC 145 ms 76484 KiB
testcase06.txt AC 142 ms 76996 KiB
testcase07.txt AC 138 ms 77252 KiB
testcase08.txt AC 153 ms 77992 KiB
testcase09.txt AC 142 ms 77748 KiB
testcase10.txt AC 147 ms 77836 KiB
testcase11.txt AC 140 ms 76596 KiB
testcase12.txt AC 141 ms 77160 KiB
testcase13.txt AC 144 ms 77380 KiB
testcase14.txt AC 145 ms 77744 KiB
testcase15.txt AC 141 ms 77024 KiB
testcase16.txt AC 116 ms 75076 KiB
testcase17.txt AC 144 ms 77104 KiB
testcase18.txt AC 118 ms 77240 KiB
testcase19.txt AC 151 ms 77368 KiB
testcase20.txt AC 124 ms 74796 KiB
testcase21.txt AC 143 ms 77048 KiB
testcase22.txt AC 130 ms 78468 KiB
testcase23.txt AC 144 ms 77020 KiB
testcase24.txt AC 121 ms 78292 KiB
testcase25.txt AC 110 ms 74888 KiB
testcase26.txt AC 108 ms 74792 KiB
testcase27.txt AC 117 ms 74888 KiB
testcase28.txt AC 123 ms 76016 KiB
testcase29.txt AC 117 ms 74852 KiB
testcase30.txt AC 111 ms 74888 KiB
testcase31.txt AC 142 ms 77012 KiB
testcase32.txt AC 146 ms 79540 KiB
testcase33.txt AC 317 ms 164132 KiB
testcase34.txt AC 536 ms 261976 KiB