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;
typedef pair<int,int> P;
map<P,int> mp;
map<P,bool> vis;
int main() {
int n,t;
scanf("%d %d",&n,&t);
for(int i=0;i<n;i++) {
int x,y;
scanf("%d %d",&x,&y);
mp[P(x,y)]=i;
}
P st=(*mp.begin()).first;
vis[st]=true;
deque<P> q;
q.push_front(st);
vector<int> ret;
while (!q.empty()) {
P now=q.front();
ret.push_back(mp[now]);
q.pop_front();
int x=now.first;
int y=now.second;
if (mp.find(P(x,y-1))!=mp.end()&&!vis[P(x,y-1)]) {
q.push_front(P(x,y-1));
vis[P(x,y-1)]=true;
}
if (mp.find(P(x,y+1))!=mp.end()&&!vis[P(x,y+1)]) {
q.push_front(P(x,y+1));
vis[P(x,y+1)]=true;
}
for(int d=-1;d<=1;d++) {
if (mp.find(P(x+1,y+d))!=mp.end()&&!vis[P(x+1,y+d)]) {
q.push_back(P(x+1,y+d));
vis[P(x+1,y+d)]=true;
}
if (mp.find(P(x-1,y+d))!=mp.end()&&!vis[P(x-1,y+d)]) {
q.push_back(P(x-1,y+d));
vis[P(x-1,y+d)]=true;
}
}
}
if (ret.size()!=n) {
printf("NO");
}
else {
printf("YES\n");
for(int i=0;i<n;i++) {
printf("%d\n",ret[i]+1);
}
}
}
Compilation message (stderr)
skyscrapers.cpp: In function 'int main()':
skyscrapers.cpp:46:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
46 | if (ret.size()!=n) {
| ~~~~~~~~~~^~~
skyscrapers.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
10 | scanf("%d %d",&n,&t);
| ~~~~~^~~~~~~~~~~~~~~
skyscrapers.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | scanf("%d %d",&x,&y);
| ~~~~~^~~~~~~~~~~~~~~
# | 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... |