Untitled
unknown
plain_text
3 years ago
1.1 kB
11
Indexable
#include<bits/stdc++.h>
#define MAX 1000
#define pii pair< int , int >
using namespace std;
int fx[] = { 1, -1, 0, 0 };
int fy[] = { 0, 0, 1, -1 };
char cell[100][100];
int dis[100][100];
int vis[100][100];
int row, col;
void BFS ( int sx, int sy )
{
memset(vis, 0, sizeof(vis));
vis[sx][sy] = 1 ;
dis[sx][sy] = 0;
queue<pair<int,int>>q;
q.push({sx,sy});
while( !q.empty() )
{
pair< int, int > top;
top = q.front();
q.pop();
for( int k = 0 ; k<4 ; k ++ )
{
int tx = top.first+fx[k];
int ty = top.second+fy[k];
if( tx>=0 && tx<row && ty>=0 && ty<col && cell[tx][ty]== '.' && vis[tx][ty] == 0 )// "." means node ache!
{
vis[tx][ty] = 1;
dis[tx][ty]= dis[top.first][top.second] + 1;
q.push({ tx, ty });
}
}
}
}
int main()
{
FastIO;
cin>>row>>col;
for( int i = 0 ; i<row ; i++ )
{
for( int j = 0 ; j<col ; j++ )
{
cin >> cell[i][j];
}
}
}Editor is loading...