Observing Objects
시간 제한2초메모리 제한1024 MB
N×M 격자에서 8방향으로 연결된 같은 색 픽셀 덩어리의 개수를 센다.
문제
In image processing fundamentals, determining the region where an object is located is crucial.
You are given a screen of size , consisting of pixels. Each pixel at position has a specific RGB value represented by three integers: (Red), (Green), and (Blue). Each color component is an integer in the range.
The task is to identify the number of distinct objects on the screen. Two pixels are considered part of the same object if their RGB values are identical and connected in one of the possible directions: up, down, left, right, and the diagonals.
An object is defined as a group of connected pixels that meet the above criteria. Write a program to determine the number of distinct objects on the screen.
입력
The first line contains two space-separated integers, and , denoting the size of the image. ()
The following lines contain integers, where each line has space-separated integers, denoting the RGB value of each pixel. Here, the -th, the -th, and the -th integer of the -th row denotes , , and , respectively. ()
출력
Output the total number of distinct objects in the screen.