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 endl '\n'
#define int long long
typedef long long ll;
const int M = 2e6 + 5, MOD = 1e9+7;
struct point {int x, y, i;};
int vis[M], cnt, nig[M];
vector<int> node[M], ar;
int lca[M][30], d[M];
void dfs2(int u) {
vis[u] = true;
for (int v:node[u]) {
if (!vis[v]) {
d[v] = d[u]+1;
lca[v][0] = u;
for (int i = 1; i <= 20; i++) {
lca[v][i] = lca[lca[v][i-1]][i-1];
}
dfs2(v);
}
}
}
int get(int a, int b) {
if (d[a] < d[b]) swap(a, b);
int l = 0;
while (d[a]-d[b] > 0) {
if ((d[a]-d[b])&(1<<l)) a = lca[a][l];
l++;
}
l = 20;
while (a != b) {
while (l >= 0 && lca[a][l] == lca[b][l]) l--;
if (l < 0) return lca[a][0];
a = lca[a][l];
b = lca[b][l];
} return a;
}
vector<int> ans;
void dfs(int s) {
vis[s] = true;
int mx = 0;
for (int i:node[s]) {
if (vis[i]) {
mx = max(mx, d[i]+d[s]-2*d[get(i, s)] - 1);
}
}
if (mx&&!nig[s]) {
nig[s] = mx;
vis[s] = 0;
ar.push_back(s);
} else {
cnt++;
ans.push_back(s);
for (int i:node[s]) if (!vis[i] && !nig[i]) dfs(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]);
}
dfs2(1);
for (int i = 1; i <= n; i++) vis[i] = 0;
dfs(1);
while (ar.size()) {
sort(ar.begin(), ar.end(), [](int a, int b) {return nig[a] < nig[b];});
vector<int> tmp = {};
swap(ar, tmp);
for (int i:tmp) dfs(i);
}
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 (stderr)
skyscrapers.cpp: In function 'int main()':
skyscrapers.cpp:83:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | for (int j = 1; j < p.size(); j++) {
| ~~^~~~~~~~~~
skyscrapers.cpp:101:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
101 | for (int j = 1; j < p.size(); j++) {
| ~~^~~~~~~~~~
skyscrapers.cpp:119:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
119 | for (int j = 1; j < p.size(); j++) {
| ~~^~~~~~~~~~
skyscrapers.cpp:137:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
137 | for (int j = 1; j < p.size(); j++) {
| ~~^~~~~~~~~~
# | 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... |