Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <utility>
- #define pb push_back
- #include <iostream>
- #include <algorithm>
- #include <queue>
- #include <vector>
- #include <string>
- #include <fstream>
- using namespace std;
- int main() {
- ifstream cin("input.txt");
- ofstream cout("output.txt");
- int n, m;
- cin >> n >> m;
- int trees;
- cin >> trees;
- queue<pair<int, int> > q;
- bool visited[2005][2005];
- for (int i=0; i < trees; i++) {
- int x, y;
- cin >> x >> y;
- q.push(pair<int, int>(x, y));
- visited[x][y] = 1;
- }
- int a1[4] = {1, 0, -1, 0};
- int a2[4] = {0, 1, 0, -1};
- int x, y;
- while (!q.empty()) {
- pair<int, int> v = q.front();
- x = v.first;
- y = v.second;
- q.pop();
- for (int i=0; i<4; i++) {
- int nx = a1[i] + x;
- int ny = a2[i] + y;
- if (nx >= 1 && nx <= n && ny >= 1 && ny <= m && !visited[nx][ny]) {
- visited[x][y] = 1;
- q.push(pair<int, int>(nx, ny));
- }
- }
- }
- cout << x << " " << y << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment