void solution(int N)
{
int general, colorblind;
general = countGroups(N, canGo);
fill(&visited[0][0], &visited[MAXSIZE - 1][MAXSIZE], false);
colorblind = countGroups(N, canGoColorBlind);
cout << general << " " << colorblind;
}
int countGroups(int N, bool(*canGoFunc)(pair<int, int> curr, pair<int, int> next, int N))
{
int result = 0;
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
{
pair<int, int> curr = { i, j };
if (!visited[curr.first][curr.second])
{
bfs(curr, N, canGoFunc);
result++;
}
}
return result;
}
void bfs(pair<int,int> start, const int N, bool(*canGoFunc)(pair<int, int> curr, pair<int, int> next, int N))
{
queue<pair<int, int>> q;
q.push(start);
visited[start.first][start.second] = true;
while (!q.empty())
{
pair<int, int> curr = q.front();
q.pop();
for (auto& dir : Directions)
{
pair<int, int> next = { curr.first + dir.first , curr.second + dir.second };
if (canGoFunc(curr, next, N))
{
visited[next.first][next.second] = true;
q.push(next);
}
}
}
}
bool canGo(pair<int, int> curr, pair<int, int> next, int N)
{
if (next.first < 0 || N <= next.first)
return false;
if (next.second < 0 || N <= next.second)
return false;
if (graph[next.first][next.second] != graph[curr.first][curr.second])
return false;
return !visited[next.first][next.second];
}
bool canGoColorBlind(pair<int, int> curr, pair<int, int> next, int N)
{
if (next.first < 0 || N <= next.first)
return false;
if (next.second < 0 || N <= next.second)
return false;
if ((graph[next.first][next.second] != graph[curr.first][curr.second]) &&
(graph[next.first][next.second] == 'B' || graph[curr.first][curr.second] == 'B'))
return false;
return !visited[next.first][next.second];
}