const
dx:array[1..4]of integer=(-1,0,1,0);
dy:array[1..4]of integer=(0,1,0,-1);
var
v:array[0..51,0..51]of boolean;
vx:array[0..51,0..51]of 0..1;
sum:array[0..51,0..51]of longint;
setx:array[1..51,1..51]of 0..1;
ans:integer;
max:integer;
ch:string;
n,m,x1,y1,i,j,k,x,y:longint;
procedure dfs(x,y:longint);
Begin
for k:=1 to 4 do
begin
if (x+dx[k]<0)or(x+dx[k]>n)or(y+dy[k]<0)or(y+dy[k]>n) then exit else
if (v[x+dx[k],y+dy[k]]=true)and(vx[x+dx[k],y+dy[k]]=1) then
begin
vx[x+dx[k],y+dy[k]]:=0;
inc(sum[x+dx[k],y+dy[k]],1);
dfs(x+dx[k],y+dy[k]);
vx[x+dx[k],y+dy[k]]:=1;
end;
end;
end;
Begin
readln(n,m);
for i:=1 to m+1 do
begin
v[0,i]:=false;
v[n+1,i]:=false;
end;
for i:=0 to n+1 do
begin
v[i,0]:=false;
v[i,m+1]:=false;
end;
for i:=1 to n do
begin
readln(ch);
for j:=1 to m do
begin
if ch[j]='.' then v[i,j]:=true;
if ch[j]='#' then v[i,j]:=false;
if ch[j]='R' then begin v[i,j]:=true; setx[i,j]:=1; end;
end; end;
filldword(sum,sizeof(sum)div 4,0);
for i:=1 to n do
for j:=1 to m do
begin
if setx[i,j]=1 then begin
fillchar(vx,sizeof(vx),1);
vx[i,j]:=0;
sum[i,j]:=1;
dfs(i,j);
end;
end;
max:=0;
for i:=1 to n do
for j:=1 to m do
if sum[i,j]>max then max:=sum[i,j];
writeln(max);
end.
#include<cstring>
using namespace std;
struct node
{
int adj;
struct node *next;
};
node *g[10000];
bool visited[10000]={0};
void dfs(int x)
{
node *p;
p=new node;
cout<<x<<' ';
visited[x]=1;
p=g[x];
while(p)
{
if(!visited[p->adj])
dfs(p->adj);
p=p->next;
}
}
int main()
{
node *p;
int n,en,i,x,y;
cin>>n>>en;
memset(g,0,sizeof(g));
for(i=0;i<en;i++)
{
cin>>x>>y;
p=new node;
p->adj=y;
p->next=g[x];
g[x]=p;
p=new node;
p->adj=x;
p->next=g[y];
g[y]=p;
}
for(i=1;i<=n;i++)
if(!visited[i])
dfs(i);
cout<<endl;
system("pause");
return 0;
}
program exam;
const
s:array [1..4,1..2] of longint=((0,1),(1,0),(-1,0),(0,-1));
var
n,m,i,j,k,tot,ans:longint;
a:array [1..50,1..50] of char;
d:array [1..2500,1..2] of longint;
procedure doit(x,y:longint);
var
i:longint;
begin
if a[x,y]='R' then inc(tot);
a[x,y]:='#';
for i:=1 to 4 do
if (x+s[i,1]>0) and (x+s[i,1]<=n) and (y+s[i,2]>0) and (y+s[i,2]<=m) and
(a[x+s[i,1],y+s[i,2]]<>'#') then doit(x+s[i,1],y+s[i,2]);
end;
begin
readln(n,m); k:=0;
for i:=1 to n do begin
for j:=1 to m do begin
read(a[i,j]);
if a[i,j]='R' then begin
inc(k); d[k,1]:=i; d[k,2]:=j;
end; end;
readln; end;
ans:=0;
for i:=1 to k do
if a[d[i,1],d[i,2]]='R' then begin
tot:=0;
doit(d[i,1],d[i,2]);
if ans<tot then ans:=tot; end;
writeln(ans);
readln;
end.