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>
typedef long long ll;
using namespace std;
set<pair<int, int>> st;
int dx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dy[8] = {1, 0, -1, 1, -1, 1, 0, -1};
pair<int, int> a[150150];
map<pair<int, int>, int> mp;
bool visited[150150];
int main(){
int n, t;
scanf("%d %d", &n, &t);
for (int i=0;i<n;i++){
scanf("%d %d", &a[i].first, &a[i].second);
mp[a[i]] = i;
}
auto iter = min_element(a, a+n);
st.insert(*iter); visited[iter-a] = 1;
vector<int> ans;
while(!st.empty()){
auto p = *st.begin(); st.erase(st.begin());
ans.push_back(mp[p]);
for (int k=0;k<8;k++){
int nx = p.first + dx[k], ny = p.second + dy[k];
if (mp.find(make_pair(nx, ny))!=mp.end()){
pair<int, int> tmp = {nx, ny};
if (!visited[mp[tmp]]){
st.insert(tmp);
visited[mp[tmp]] = 1;
}
}
}
}
if ((int)ans.size()<n) printf("NO\n");
else{
printf("YES\n");
for (auto &x:ans) printf("%d\n", x+1);
}
return 0;
}
Compilation message (stderr)
skyscrapers.cpp: In function 'int main()':
skyscrapers.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | scanf("%d %d", &n, &t);
| ~~~~~^~~~~~~~~~~~~~~~~
skyscrapers.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | scanf("%d %d", &a[i].first, &a[i].second);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |