Skip to content

Instantly share code, notes, and snippets.

@Shafaet
Last active August 29, 2015 13:56
Show Gist options
  • Save Shafaet/9167648 to your computer and use it in GitHub Desktop.
Save Shafaet/9167648 to your computer and use it in GitHub Desktop.
#define pii pair<int,int>
int fx[]={1,-1,0,0}; //ডিরেকশন অ্যারে
int fy[]={0,0,1,-1};
int cell[100][100]; //cell[x][y] যদি -১ হয় তাহলে সেলটা ব্লক
int d[100][100],vis[100][100];
int row,col;
void bfs(int sx,int sy)
{
mem(vis,0);
vis[sx][sy]=1;
queue<pii>q;
q.push(pii(sx,sy));
while(!q.empty())
{
pii top=q.front(); q.pop();
rep(k,4)
{
int tx=top.uu+fx[k];
int ty=top.vv+fy[k];
if(tx>=0 and tx<row and ty>=0 and ty<col and cell[tx][ty]!=-1 and vis[tx][ty]==0)
{
vis[tx][ty]=1;
d[tx][ty]=d[top.uu][top.vv]+1;
q.push(pii(tx,ty));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment