#include <bits/stdc++.h>
using namespace std;
int wx[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, wy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
signed main(){
int n, t; cin >> n >> t;
vector<pair<int, int>> a(n);
map<int, map<int, int>> mp;
vector<int> chk(n);
vector<int> ans;
vector<int> mn = {(int)2e9, (int)2e9};
for(int i = 0; i < n; ++i){
cin >> a[i].first >> a[i].second;
mp[a[i].first][a[i].second] = i;
mn = min(mn, vector<int>{a[i].first, a[i].second, i});
}
priority_queue<vector<int>> pq;
pq.push(mn);
while(!pq.empty()){
auto top = pq.top(); pq.pop();
if(chk[top[2]]){
continue;
}
chk[top[2]] = 1;
ans.push_back(top[2]);
--mp[top[0]][top[1]];
for(int i = 0; i < 8; ++i){
int nx = top[0] + wx[i], ny = top[1] + wy[i];
if(mp[nx][ny]){
pq.push({nx, ny, mp[nx][ny]});
}
}
}
if((int)ans.size() != n){
cout << "NO\n";
}
else{
cout << "YES\n";
for(auto&i:ans){
cout << i + 1 << '\n';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
ans=YES N=1 |
2 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
ans=YES N=1 |
2 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
ans=YES N=1 |
2 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
596 KB |
ans=NO N=1934 |
2 |
Correct |
3 ms |
468 KB |
ans=NO N=1965 |
3 |
Incorrect |
6 ms |
500 KB |
Contestant did not find solution |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
ans=YES N=1 |
2 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
162 ms |
6820 KB |
ans=NO N=66151 |
2 |
Correct |
48 ms |
4692 KB |
ans=NO N=64333 |
3 |
Incorrect |
199 ms |
6792 KB |
Contestant did not find solution |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
596 KB |
ans=NO N=1934 |
2 |
Correct |
3 ms |
468 KB |
ans=NO N=1965 |
3 |
Incorrect |
6 ms |
500 KB |
Contestant did not find solution |
4 |
Halted |
0 ms |
0 KB |
- |