This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//bayemirov
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
#define pb push_back
#define f first
#define s second
const int N = 2e5;
const int INF = 1e9;
const int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, -1, 1};
vector<pair<int, int>> points;
map<int, map<int, int>> id;
bool was[N];
int n, t, d[N];
bool ok(int j) {
return j > 0 && !was[j];
}
bool check1(int v = 0, int cnt = 1, bool res = 0) {
was[v] = 1;
if (cnt == n) return 1;
for (int i = 0; i < 8; i++) {
int new_x = points[v].f + dx[i];
int new_y = points[v].s + dy[i];
if (ok(id[new_x][new_y]))
res |= check1(id[new_x][new_y], cnt + 1);
}
return res;
}
bool check(auto p) {
for (int i = 0; i < 4; i++) {
int new_x = p.f + dx[i];
int new_y = p.s + dy[i];
if (!ok(id[new_x][new_y]))
return 1;
}
return 0;
}
bool check2() {
for (auto p : points) {
if (!check(p))
return 0;
}
return 1;
}
void bfs() {
queue<int> q;
q.push(0);
fill(d, d + n, INF);
d[0] = 0;
while (!q.empty()) {
int v = q.front();
q.pop();
for (int i = 0; i < 8; i++) {
int new_x = points[v].f + dx[i];
int new_y = points[v].s + dy[i];
int u = id[new_x][new_y];
if (u > 0 && d[u] > d[v] + 1) {
d[u] = d[v] + 1;
q.push(u);
}
}
}
}
vector<int> get(vector<int> res = {}) {
int v = n - 1;
while (v) {
res.pb(v);
int best = -1;
for (int i = 0; i < 8; i++) {
int new_x = points[v].f + dx[i];
int new_y = points[v].s + dy[i];
int u = id[new_x][new_y];
if (u >= 0 && was[u] && d[u] < d[v])
best = max(best, u);
}
v = best;
}
res.pb(0);
reverse(res.begin(), res.end());
return res;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
cin >> n >> t;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
points.pb({x, y});
id[x][y] = i;
}
if (!(check1() & check2())) cout << "NO", exit(0);
cout << "YES\n";
bfs();
auto ans = get();
for (auto x : ans) cout << x + 1 << "\n";
return 0;
}
# | 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... |