#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
typedef long long ll;
const int M = 2e7 + 5, MOD = 1e9+7;
struct point {int x, y, i;};
int vis[M], cnt, nig[M];
vector<int> node[M];
vector<int> ans;
void bfs(int s) {
deque<int> q;
q.push_back(s);
vis[s] = true;
while (!q.empty()) {
int t = q.front();
cnt++;
q.pop_back();
int pp = 0;
for (int i:node[t]) pp += vis[i];
if (pp >= 2 && !vis[nig[t]]) {
q.push_front(t);
nig[t] = true;
} else {
ans.push_back(t);
for (int i:node[t]) {
if (!vis[i]) {
vis[i] = true;
q.push_back(i);
}
}
}
}
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
srand(time(0));
int n, t;
cin >> n >> t;
vector<point> v(n);
for (auto&i:v) cin >> i.x >> i.y;
int ind = 1; for (auto&i:v) i.i = ind++;
vector<point> p;
sort(v.begin(), v.end(), [](point a, point b){if (a.y == b.y) return a.x < b.x; return a.y < b.y;});
for (int i = 0; i < n; i++) {
while (i < n && (!i || v[i].y == v[i-1].y)) {
p.push_back(v[i++]);
}
for (int j = 1; j < p.size(); j++) {
if (p[j-1].x+1 == p[j].x) {
node[p[j].i].push_back(p[j-1].i);
node[p[j-1].i].push_back(p[j].i);
}
}
p.clear();
p.push_back(v[i]);
}
p.clear();
sort(v.begin(), v.end(), [](point a, point b){if (a.x == b.x) return a.y < b.y; return a.x < b.x;});
for (int i = 0; i < n; i++) {
while (i < n && (!i || v[i].x == v[i-1].x)) {
p.push_back(v[i++]);
}
for (int j = 1; j < p.size(); j++) {
if (p[j-1].y+1 == p[j].y) {
node[p[j].i].push_back(p[j-1].i);
node[p[j-1].i].push_back(p[j].i);
}
}
p.clear();
p.push_back(v[i]);
}
p.clear();
sort(v.begin(), v.end(), [](point a, point b){if ((a.x+a.y) == (b.x+b.y)) return a.x < b.x; return a.x+a.y < b.x+b.y;});
for (int i = 0; i < n; i++) {
while (i < n && (!i || (v[i].x+v[i].y) == (v[i-1].x+v[i-1].y))) {
p.push_back(v[i++]);
}
for (int j = 1; j < p.size(); j++) {
if (p[j-1].x+1 == p[j].x) {
node[p[j].i].push_back(p[j-1].i);
node[p[j-1].i].push_back(p[j].i);
}
}
p.clear();
p.push_back(v[i]);
}
p.clear();
sort(v.begin(), v.end(), [](point a, point b){if ((a.x-a.y) == (b.x-b.y)) return a.x < b.x; return a.x-a.y < b.x-b.y;});
for (int i = 0; i < n; i++) {
while (i < n && (!i || (v[i].x-v[i].y) == (v[i-1].x-v[i-1].y))) {
p.push_back(v[i++]);
}
for (int j = 1; j < p.size(); j++) {
if (p[j-1].x+1 == p[j].x) {
node[p[j].i].push_back(p[j-1].i);
node[p[j-1].i].push_back(p[j].i);
}
}
p.clear();
p.push_back(v[i]);
}
bfs(1);
if (cnt == n) {
cout << "YES" << endl;
for (int i:ans) cout << i << endl;
} else cout << "NO" << endl;
return 0;
}
/*
3 2
0 0
0 1
0 2
*/
Compilation message
skyscrapers.cpp: In function 'int main()':
skyscrapers.cpp:55:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for (int j = 1; j < p.size(); j++) {
| ~~^~~~~~~~~~
skyscrapers.cpp:73:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for (int j = 1; j < p.size(); j++) {
| ~~^~~~~~~~~~
skyscrapers.cpp:91:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | for (int j = 1; j < p.size(); j++) {
| ~~^~~~~~~~~~
skyscrapers.cpp:109:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
109 | for (int j = 1; j < p.size(); j++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
206 ms |
469960 KB |
ans=YES N=1 |
2 |
Incorrect |
219 ms |
469936 KB |
Contestant did not find solution |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
206 ms |
469960 KB |
ans=YES N=1 |
2 |
Incorrect |
219 ms |
469936 KB |
Contestant did not find solution |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
206 ms |
469960 KB |
ans=YES N=1 |
2 |
Incorrect |
219 ms |
469936 KB |
Contestant did not find solution |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
213 ms |
470096 KB |
ans=NO N=1934 |
2 |
Correct |
224 ms |
470052 KB |
ans=NO N=1965 |
3 |
Incorrect |
215 ms |
470220 KB |
Contestant did not find solution |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
206 ms |
469960 KB |
ans=YES N=1 |
2 |
Incorrect |
219 ms |
469936 KB |
Contestant did not find solution |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
268 ms |
476716 KB |
ans=NO N=66151 |
2 |
Correct |
265 ms |
472260 KB |
ans=NO N=64333 |
3 |
Incorrect |
277 ms |
477304 KB |
Contestant did not find solution |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
213 ms |
470096 KB |
ans=NO N=1934 |
2 |
Correct |
224 ms |
470052 KB |
ans=NO N=1965 |
3 |
Incorrect |
215 ms |
470220 KB |
Contestant did not find solution |
4 |
Halted |
0 ms |
0 KB |
- |