This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define size(x) (int)x.size()
template<class S, class T>
bool chmin(S &a, const T &b) {
return a > b ? (a = b) == b : false;
}
template<class S, class T>
bool chmax(S &a, const T &b) {
return a < b ? (a = b) == b : false;
}
const vector<int> dx = {-1, -1, -1, 0, 0, 1, 1, 1};
const vector<int> dy = {-1, 0, 1, -1, 1, -1, 0, 1};
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, t; cin >> n >> t;
int x[n], y[n];
map<int, map<int, bool>> vis;
map<int, map<int, int>> used;
map<int, vector<int>> g;
for (int i = 0; i < n; ++i) {
cin >> x[i] >> y[i];
used[x[i]][y[i]] = i + 1;
g[x[i] + y[i]].push_back(i);
}
for (int i = 0; i < n; ++i) {
bool flag = false;
for (int j = 0; j < 8; ++j) {
if (used[x[i] + dx[j]][y[i] + dy[j]]) {
flag |= true;
}
}
if (!flag) {
cout << "NO";
return 0;
}
}
cout << "YES\n";
queue<int> q;
q.push(0);
vis[x[0]][y[0]] = true;
while (!q.empty()) {
int i = q.front();
cout << i + 1 << '\n';
q.pop();
for (int j = 0; j < 8; ++j) {
int to_x = x[i] + dx[j], to_y = y[i] + dy[j];
if (used[to_x][to_y]) {
if (!vis[to_x][to_y]) {
vis[to_x][to_y] = true;
q.push(used[to_x][to_y] - 1);
}
}
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |