#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
struct Point{
int x, y, i;
Point(){}
Point(int _x, int _y, int _i): x(_x), y(_y), i(_i) {}
bool operator<(const Point &P) const{
return tie(x, y) < tie(P.x, P.y);
}
}a[150150];
vector<int> ans;
map<int, map<int, int>> mp;
bool visited[150150];
int n, dx[8] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[8] = {0, 0, 1, -1, -1, 1, -1, 1};
int bx, by, cnt, b[2020][2020], out[2020][2020], dfn[150150], on[150150], up[150150], cut[150150], ok[150150];
int dfs0(int s){
visited[s] = 1;
int ret = 1;
for (int k=0;k<8;k++){
int nx = a[s].x + dx[k], ny = a[s].y + dy[k];
if (mp[nx][ny] && !visited[mp[nx][ny]]){
ret += dfs0(mp[nx][ny]);
}
}
return ret;
}
void dfs1(int x, int y, int t){
if (x<0 || x>bx) return;
if (y<0 || y>by) return;
if (out[x][y]) return;
out[x][y] = t;
if (b[x][y]) return;
for (int k=0;k<4;k++){
int nx = x + dx[k], ny = y + dy[k];
dfs1(nx, ny, t);
}
}
void compress(){
vector<int> X, Y;
for (int i=1;i<=n;i++){
X.push_back(a[i].x);
Y.push_back(a[i].y);
}
sort(X.begin(), X.end());
sort(Y.begin(), Y.end());
X.erase(unique(X.begin(), X.end()), X.end());
Y.erase(unique(Y.begin(), Y.end()), Y.end());
for (int i=1;i<=n;i++){
a[i].x = lower_bound(X.begin(), X.end(), a[i].x) - X.begin() + 1;
a[i].y = lower_bound(Y.begin(), Y.end(), a[i].y) - Y.begin() + 1;
b[a[i].x][a[i].y] = i;
on[i] = 1;
}
bx = X.size() + 1;
by = Y.size() + 1;
int t = 0;
for (int i=0;i<=bx;i++){
for (int j=0;j<=by;j++) if (!out[i][j] && !b[i][j]){
dfs1(i, j, ++t);
}
}
ok[1] = 1;
}
void dfs(int x, int y, int pa = -1){
int s = b[x][y];
visited[s] = 1;
dfn[s] = ++cnt;
up[s] = dfn[s];
cut[s] = 0;
int child = 0;
for (int k=0;k<8;k++){
int nx = x + dx[k], ny = y + dy[k];
if (!b[nx][ny] || !on[b[nx][ny]]) continue;
int nnum = b[nx][ny];
if (visited[nnum] && nnum!=pa){
up[s] = min(up[s], dfn[nnum]);
}
else if (!visited[nnum]){
child++;
dfs(nx, ny, s);
up[s] = min(up[s], up[nnum]);
if (up[nnum]==dfn[nnum] && pa!=-1) cut[s] = 1;
}
}
if (pa==-1 && child>1) cut[s] = 1;
}
void solve(){
cnt = 0;
fill(visited+1, visited+n+1, 0);
for (int i=1;i<=n;i++) if (on[i]) {dfs(a[i].x, a[i].y); break;}
/*for (int i=1;i<=n;i++) printf("%d %d %d / ", on[i], out[a[i].x][a[i].y], cut[i]);
printf("\n");*/
for (int i=n;i;i--) if (on[i] && ok[out[a[i].x][a[i].y]] && !cut[i]){
ans.push_back(i);
on[i] = 0;
for (int k=0;k<4;k++){
int nx = a[i].x + dx[k], ny = a[i].y + dy[k];
if (!b[nx][ny]) ok[out[nx][ny]] = 1;
else out[nx][ny] = 1;
}
return;
}
assert(0);
}
int main(){
int typ;
scanf("%d %d", &n, &typ);
for (int i=1;i<=n;i++){
scanf("%d %d", &a[i].x, &a[i].y);
a[i].i = i;
mp[a[i].x][a[i].y] = i;
}
if (dfs0(1)!=n) {printf("NO\n"); return 0;}
compress();
for (int i=1;i<=n;i++) solve();
reverse(ans.begin(), ans.end());
printf("YES\n");
for (auto &x:ans) printf("%d\n", x);
return 0;
}
Compilation message
skyscrapers.cpp: In function 'int main()':
skyscrapers.cpp:130:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
130 | scanf("%d %d", &n, &typ);
| ~~~~~^~~~~~~~~~~~~~~~~~~
skyscrapers.cpp:133:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
133 | scanf("%d %d", &a[i].x, &a[i].y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
340 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
212 KB |
ans=NO N=4 |
4 |
Correct |
1 ms |
340 KB |
ans=YES N=5 |
5 |
Correct |
0 ms |
340 KB |
ans=YES N=9 |
6 |
Correct |
0 ms |
340 KB |
ans=YES N=5 |
7 |
Correct |
1 ms |
212 KB |
ans=NO N=9 |
8 |
Correct |
1 ms |
212 KB |
ans=NO N=10 |
9 |
Incorrect |
1 ms |
340 KB |
Full cells must be connected |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
340 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
212 KB |
ans=NO N=4 |
4 |
Correct |
1 ms |
340 KB |
ans=YES N=5 |
5 |
Correct |
0 ms |
340 KB |
ans=YES N=9 |
6 |
Correct |
0 ms |
340 KB |
ans=YES N=5 |
7 |
Correct |
1 ms |
212 KB |
ans=NO N=9 |
8 |
Correct |
1 ms |
212 KB |
ans=NO N=10 |
9 |
Incorrect |
1 ms |
340 KB |
Full cells must be connected |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
340 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
212 KB |
ans=NO N=4 |
4 |
Correct |
1 ms |
340 KB |
ans=YES N=5 |
5 |
Correct |
0 ms |
340 KB |
ans=YES N=9 |
6 |
Correct |
0 ms |
340 KB |
ans=YES N=5 |
7 |
Correct |
1 ms |
212 KB |
ans=NO N=9 |
8 |
Correct |
1 ms |
212 KB |
ans=NO N=10 |
9 |
Incorrect |
1 ms |
340 KB |
Full cells must be connected |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
ans=NO N=1934 |
2 |
Correct |
1 ms |
340 KB |
ans=NO N=1965 |
3 |
Incorrect |
60 ms |
1032 KB |
Full cells must be connected |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
340 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
212 KB |
ans=NO N=4 |
4 |
Correct |
1 ms |
340 KB |
ans=YES N=5 |
5 |
Correct |
0 ms |
340 KB |
ans=YES N=9 |
6 |
Correct |
0 ms |
340 KB |
ans=YES N=5 |
7 |
Correct |
1 ms |
212 KB |
ans=NO N=9 |
8 |
Correct |
1 ms |
212 KB |
ans=NO N=10 |
9 |
Incorrect |
1 ms |
340 KB |
Full cells must be connected |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
107 ms |
9912 KB |
ans=NO N=66151 |
2 |
Correct |
41 ms |
4220 KB |
ans=NO N=64333 |
3 |
Execution timed out |
3534 ms |
12084 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
ans=NO N=1934 |
2 |
Correct |
1 ms |
340 KB |
ans=NO N=1965 |
3 |
Incorrect |
60 ms |
1032 KB |
Full cells must be connected |
4 |
Halted |
0 ms |
0 KB |
- |