-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1743.py
More file actions
42 lines (34 loc) · 872 Bytes
/
1743.py
File metadata and controls
42 lines (34 loc) · 872 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
"""
이거 부모 노드를 찾는 union-find 하면 될듯?
"""
import sys
sys.setrecursionlimit(10 ** 6)
N,M,K = map(int,input().split())
food_position = []
food_index = {}
for i in range(K):
x,y = map(int,input().split())
food_position.append((x,y))
food_index[(x,y)] = i
parent = [i for i in range(K)]
size = [1 for _ in range(K)]
def find(x):
if parent[x] != x:
parent[x] = find(parent[x])
return parent[x]
def union(x, y):
x_root = find(x)
y_root = find(y)
if x_root != y_root:
parent[y_root] = x_root
size[x_root] += size[y_root]
dx = [-1,1,0,0]
dy = [0,0,-1,1]
for i in range(K):
x,y = food_position[i]
for j in range(4):
new_x = x + dx[j]
new_y = y + dy[j]
if (new_x, new_y) in food_position:
union(i, food_position.index((new_x, new_y)))
print(max(size))