class Graph
{
public readonly int Width;
public readonly int Height;
public bool[,] BitMap;
public List<List<Point>> Fill()
{
bool[,] history = new bool[Width, Height];
List<List<Point>> result = new List<List<Point>>();
for (int i = 0; i < Width; i++)
{
for (int j = 0; j < Height; j++)
{
if (BitMap[i, j] && !history[i, j])
result.Add(BFS(i, j, history));
}
}
return result;
}
private List<Point> BFS(int x, int y, bool[,] history)
{
List<Point> currentPoints = new List<Point>();
Queue<Point> queue = new Queue<Point>();
Point cPoint = new Point(x, y);
queue.Enqueue(cPoint);
while (queue.Count > 0)
{
Point current = queue.Dequeue();
currentPoints.Add(current);
history[current.X, current.Y] = true;
for (int i = current.X - 1; i <= current.X + 1; i++)
{
for (int j = current.Y - 1; j <= current.Y + 1; j++)
{
if (i == current.X && j == current.Y)
continue;
if (Check(i, j) && !history[i,j])
queue.Enqueue(new Point(i, j));
}
}
}
return currentPoints;
}
private bool Check(int x, int y)
{
if (x < 0 || x >= Width || y < 0 || y >= Height)
return false;
return BitMap[x, y];
}
public Graph(int width, int height)