-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBJ9205.py
More file actions
43 lines (29 loc) · 894 Bytes
/
BJ9205.py
File metadata and controls
43 lines (29 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import sys
from collections import deque
TC = int(sys.stdin.readline())
for tc in range(TC):
convList = deque([])
visited = deque([])
convCount = int(sys.stdin.readline())
home = list(map(int, sys.stdin.readline().split(' ')))
for c in range(convCount):
conv = list(map(int, sys.stdin.readline().split(' ')))
convList.append(conv)
visited.append(False)
rock = list(map(int, sys.stdin.readline().split(' ')))
result = 'sad'
q = deque([])
q.append(home)
while q:
poped = q.popleft()
if abs(rock[0] - poped[0]) + abs(rock[1] - poped[1]) <= 1000:
result = 'happy'
break
for i in range(convCount):
if not visited[i]:
if abs(convList[i][0] - poped[0]) + abs(convList[i][1] - poped[1]) <= 1000:
visited[i] = True
q.append(convList[i])
if result != 'happy':
result = 'sad'
print(result)