Untitled
unknown
c_cpp
2 years ago
1.1 kB
27
Indexable
#include <bits/stdc++.h>
using namespace std ;
queue<pair<int , int>> q;
int dx[4] = {0 , 1 , -1 , 0};
int dy[4] = {1 , 0 , 0 , -1};
const int maxn = 2e3+4;
bool mark[maxn][maxn];
int k , t , n, m , ans1 , ans2;
bool check(int x , int y){
if(x > n || y > m || x <= 0 || y <= 0 || mark[k][t])
return false;
return true;
}
void bfs(int u , int v){
mark[u][v] = true;
q.push(make_pair(u , v));
ans1 = u , ans2 = v;
while(!q.empty()){
k = q.front().first;
t = q.front().second;
q.pop();
for(int i = 0 ; i < 4 ; i++){
if(check(k + dx[i] , t + dy[i])){
mark[k+dx[i]][t+dy[i]] = true;
q.push(make_pair(k+ dx[i] , t + dy[i]));
}
}
}
}
int main(){
int c , x , y;
cin >> n >> m >> c;
for(int i = 0 ; i < c ; i++){
cin >> x >> y;
q.push(make_pair(x , y));
}
bfs(q.front().first , q.front().second);
cout << ans1 << ' ' << ans2;
return 0;
}Editor is loading...