#include #include #include #include #include #define M 405 using namespace std; fstream fin("ferma3.in",ios::in),fout("ferma3.out",ios::out); int di[]={-1,0,1,0},dj[]={0,1,0,-1}; deque > d; int cost[M*M],who[M][M]; bitset bit[M]; string s[M]; int n,m,t,ir,jr; char color; void citire(){ cin>>t>>n>>m; for(int i=0;i>s[i]; } bool ok(int i,int j){ if(-1=maxim) { color=s[c][d]; ir=a; jr=b; maxim=cost[who[c][d]]+1; } } else { if(cost[who[c][d]]+cost[who[e][f]]+1>=maxim) { color=s[c][d]; ir=a; jr=b; maxim=cost[who[c][d]]+cost[who[e][f]]+1; } } } } } } int search() { int maxim=-9999,r; for(int i=0;i