結果

問題 No.94 圏外です。(EASY)
ユーザー ckawatakckawatak
提出日時 2019-04-24 23:02:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 247 ms / 5,000 ms
コード長 1,178 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 82,400 KB
実行使用メモリ 78,096 KB
最終ジャッジ日時 2024-04-27 15:09:02
合計ジャッジ時間 3,343 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,444 KB
testcase_01 AC 40 ms
54,664 KB
testcase_02 AC 37 ms
54,404 KB
testcase_03 AC 38 ms
55,288 KB
testcase_04 AC 44 ms
63,168 KB
testcase_05 AC 50 ms
65,232 KB
testcase_06 AC 73 ms
71,296 KB
testcase_07 AC 80 ms
74,880 KB
testcase_08 AC 103 ms
77,400 KB
testcase_09 AC 129 ms
77,600 KB
testcase_10 AC 148 ms
77,772 KB
testcase_11 AC 123 ms
77,192 KB
testcase_12 AC 138 ms
77,120 KB
testcase_13 AC 135 ms
77,544 KB
testcase_14 AC 159 ms
77,460 KB
testcase_15 AC 144 ms
77,228 KB
testcase_16 AC 174 ms
77,672 KB
testcase_17 AC 151 ms
77,680 KB
testcase_18 AC 154 ms
77,440 KB
testcase_19 AC 247 ms
78,096 KB
testcase_20 AC 44 ms
54,784 KB
testcase_21 AC 41 ms
53,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt
from collections import deque

N = int(input())

points = []
for _ in range(N):
    points.append(list(map(int, input().split())))

G = []    
for i in range(N):
    graph = []
    for j in range(N):
        distance = (points[i][0]-points[j][0])**2 + \
            (points[i][1]-points[j][1])**2
        if distance <= 100:
            graph.append(j)
    G.append(graph)

def dfs(start):
    reached = []
    visited = [False for _ in range(N)]

    que = deque()
    que.append(start)
    while len(que) != 0:
        adjacent = que.popleft()
        visited[adjacent] = True
        reached.extend(G[adjacent])
        for point in G[adjacent]:
            if not visited[point]:
                que.appendleft(point)
                
    longest = 0
    for end in reached:
        distance = sqrt((points[start][0]-points[end][0])**2 + \
                        (points[start][1]-points[end][1])**2)
        longest = max(longest, distance)
        
    return longest

longest = 0
for i in range(N):
    longest = max(longest, dfs(i))

if longest == 0:
    if len(points) == 0:
        print(1)
    else:
        print(2)
else:
    print(longest+2)
0