#include <vector>
#include <stack> // dfs
#include <cstring> // memset
#include <utility> // pair
#include <algorithm> // max
#define MAX 100
using namespace std;
bool visited[MAX + 1][MAX + 1];
int dr[4] = { -1, 1, 0, 0 }; // UP DOWN LEFT RIGHT
int dc[4] = { 0, 0, -1, 1 };
int dfs(int r, int c, int m, int n, const vector<vector<int>> &picture) {
stack< pair<int, int> > st;
int nowR = r, nowC = c, nextR, nextC, i;
int area = 0;
if (!visited[nowR][nowC]) st.push(make_pair(nowR, nowC));
while (!st.empty()) {
int nowR = st.top().first;
int nowC = st.top().second;
st.pop();
if (visited[nowR][nowC]) continue;
visited[nowR][nowC] = true;
area++;
for (i = 0; i < 4; i++) {
nextR = nowR + dr[i];
nextC = nowC + dc[i];
if (0 <= nextR && nextR < m && 0 <= nextC && nextC < n) {
if (!visited[nextR][nextC] && picture[nowR][nowC] == picture[nextR][nextC]) {
st.push(make_pair(nextR, nextC));
}
}
}
}
return area;
}
vector<int> solution(int m, int n, vector<vector<int>> picture) {
int number_of_area = 0;
int max_size_of_one_area = 0;
int i, j;
memset(visited, false, sizeof(visited));
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
if (!visited[i][j] && picture[i][j]) {
number_of_area++;
max_size_of_one_area = max(max_size_of_one_area, dfs(i, j, m, n, picture));
}
}
}
vector<int> answer(2);
answer[0] = number_of_area;
answer[1] = max_size_of_one_area;
return answer;
}