#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>, vector<vector<int>>, greater<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]] -= top[2];
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 |
0 ms |
212 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
212 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
224 KB |
ans=NO N=4 |
4 |
Incorrect |
0 ms |
212 KB |
Contestant did not find solution |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
212 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
224 KB |
ans=NO N=4 |
4 |
Incorrect |
0 ms |
212 KB |
Contestant did not find solution |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
212 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
224 KB |
ans=NO N=4 |
4 |
Incorrect |
0 ms |
212 KB |
Contestant did not find solution |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
ans=NO N=1934 |
2 |
Correct |
2 ms |
340 KB |
ans=NO N=1965 |
3 |
Incorrect |
4 ms |
340 KB |
Contestant did not find solution |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
212 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
224 KB |
ans=NO N=4 |
4 |
Incorrect |
0 ms |
212 KB |
Contestant did not find solution |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
157 ms |
6448 KB |
ans=NO N=66151 |
2 |
Correct |
47 ms |
4056 KB |
ans=NO N=64333 |
3 |
Incorrect |
165 ms |
5064 KB |
Contestant did not find solution |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
ans=NO N=1934 |
2 |
Correct |
2 ms |
340 KB |
ans=NO N=1965 |
3 |
Incorrect |
4 ms |
340 KB |
Contestant did not find solution |
4 |
Halted |
0 ms |
0 KB |
- |