cyzcyz edited 9 月,1 周前
#include<bits/stdc++.h>
using namespace std;
struct Node{
int r, c;
Node(int _r, int _c){
r = _r, c = _c;
}
};
int max_n = 0;
bool v[1020][100];
int dirr[4] = {0, 0, -1, 1};
int dirc[4] = {-1, 1, 0, 0};
int w, h;
void bfs(vector<vector<char> > G, int r, int c){
int num = 1;
char cur = G[r][c];
queue<Node> q;
v[r][c]= 1;
q.push(Node(r, c));
while(!q.empty()){
int len = q.size();
for(int i = 0;i < len;i++){
for(int j = 0;j < 4;j++){
r = q.front().r + dirr[j]; c = q.front().c + dirc[j];
if(r < h && c < w){
if(!v[r][c] && G[r][c] == cur){
num++;
q.push(Node(r, c));
// cout<<r<<" "<<c<<" "<<num<<endl;
v[r][c] = 1;
}
}
}
q.pop();
}
}
max_n = max(num, max_n);
}
int main(){
char x;
cin>>w>>h;
memset(v, 0, sizeof(v));
vector<vector<char> > G(h + 1);
for(int i = 0;i < h;i++){
for(int j = 0;j < w;j++){
cin>>x;
G[i].push_back(x);
}
}
for(int i = 0;i < h;i++){
for(int j = 0;j < w;j++){
if(!v[i][j] && G[i][j] == '*') bfs(G, i, j);
}
}
cout<<max_n;
return 0;
}