#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define pb push_back
using namespace std;
const ll mx=150005;
vector<ll>v[mx];
ll cnt=0;
bool visited[mx];
void dfs (ll x)
{
cnt++;
visited[x]=1;
for(auto u:v[x])
if(visited[u]==0)
dfs(u);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n,t;
cin>>n>>t;
vector<pair<ll,ll>>b(n);
map<pair<ll,ll>,ll>mp;
for(int i=0;i<n;i++)
{
ll x,y;
cin>>x>>y;
b[i]={x,y};
mp[{x,y}]=i+1;
}
ll x[8]={1,1,1,-1,-1,-1,0,0},y[8]={1,-1,0,1,-1,0,1,-1};
ll lmt=1000000000;
for(int i=0;i<n;i++)
{
ll f=b[i].first,s=b[i].second;
for(int j=0;j<8;j++)
if(mp[{f+y[j],s+x[j]}]>0)
v[mp[{f,s}]].push_back(mp[{f+y[j],s+x[j]}]);
}
dfs(1);
if(cnt!=n)
cout<<"NO"<<endl;
else
{
cout<<"YES"<<endl;
sort(b.begin(),b.end(),greater<pair<ll,ll>>());
bool arr[n+1]={};
cnt=1;
cout<<mp[b[0]]<<endl;
arr[mp[b[0]]]=1;
while(cnt!=n)
{
for(int i=1;i<n;i++)
{
ll f=b[i].first,s=b[i].second;
if(arr[mp[{f,s}]]==1)continue;
for(int j=0;j<8;j++)
{
if(f+y[j]>lmt||s+x[j]>lmt)continue;
if(arr[mp[{f+y[j],s+x[j]}]]==1)
{
cnt++;
cout<<mp[{f,s}]<<endl;
arr[mp[{f,s}]]=1;
break;
}
}
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3796 KB |
ans=YES N=1 |
2 |
Correct |
2 ms |
3796 KB |
ans=YES N=4 |
3 |
Correct |
2 ms |
3796 KB |
ans=NO N=4 |
4 |
Correct |
2 ms |
3796 KB |
ans=YES N=5 |
5 |
Correct |
2 ms |
3796 KB |
ans=YES N=9 |
6 |
Correct |
3 ms |
3796 KB |
ans=YES N=5 |
7 |
Correct |
2 ms |
3796 KB |
ans=NO N=9 |
8 |
Correct |
2 ms |
3796 KB |
ans=NO N=10 |
9 |
Correct |
2 ms |
3796 KB |
ans=YES N=10 |
10 |
Correct |
2 ms |
3796 KB |
ans=YES N=10 |
11 |
Correct |
2 ms |
3796 KB |
ans=YES N=10 |
12 |
Correct |
3 ms |
3796 KB |
ans=YES N=9 |
13 |
Correct |
2 ms |
3852 KB |
ans=YES N=9 |
14 |
Correct |
2 ms |
3796 KB |
ans=YES N=8 |
15 |
Correct |
2 ms |
3796 KB |
ans=YES N=8 |
16 |
Correct |
2 ms |
3796 KB |
ans=NO N=2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3796 KB |
ans=YES N=1 |
2 |
Correct |
2 ms |
3796 KB |
ans=YES N=4 |
3 |
Correct |
2 ms |
3796 KB |
ans=NO N=4 |
4 |
Correct |
2 ms |
3796 KB |
ans=YES N=5 |
5 |
Correct |
2 ms |
3796 KB |
ans=YES N=9 |
6 |
Correct |
3 ms |
3796 KB |
ans=YES N=5 |
7 |
Correct |
2 ms |
3796 KB |
ans=NO N=9 |
8 |
Correct |
2 ms |
3796 KB |
ans=NO N=10 |
9 |
Correct |
2 ms |
3796 KB |
ans=YES N=10 |
10 |
Correct |
2 ms |
3796 KB |
ans=YES N=10 |
11 |
Correct |
2 ms |
3796 KB |
ans=YES N=10 |
12 |
Correct |
3 ms |
3796 KB |
ans=YES N=9 |
13 |
Correct |
2 ms |
3852 KB |
ans=YES N=9 |
14 |
Correct |
2 ms |
3796 KB |
ans=YES N=8 |
15 |
Correct |
2 ms |
3796 KB |
ans=YES N=8 |
16 |
Correct |
2 ms |
3796 KB |
ans=NO N=2 |
17 |
Incorrect |
2 ms |
3796 KB |
Added cell 17 (1,2) not reachable from infinity |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3796 KB |
ans=YES N=1 |
2 |
Correct |
2 ms |
3796 KB |
ans=YES N=4 |
3 |
Correct |
2 ms |
3796 KB |
ans=NO N=4 |
4 |
Correct |
2 ms |
3796 KB |
ans=YES N=5 |
5 |
Correct |
2 ms |
3796 KB |
ans=YES N=9 |
6 |
Correct |
3 ms |
3796 KB |
ans=YES N=5 |
7 |
Correct |
2 ms |
3796 KB |
ans=NO N=9 |
8 |
Correct |
2 ms |
3796 KB |
ans=NO N=10 |
9 |
Correct |
2 ms |
3796 KB |
ans=YES N=10 |
10 |
Correct |
2 ms |
3796 KB |
ans=YES N=10 |
11 |
Correct |
2 ms |
3796 KB |
ans=YES N=10 |
12 |
Correct |
3 ms |
3796 KB |
ans=YES N=9 |
13 |
Correct |
2 ms |
3852 KB |
ans=YES N=9 |
14 |
Correct |
2 ms |
3796 KB |
ans=YES N=8 |
15 |
Correct |
2 ms |
3796 KB |
ans=YES N=8 |
16 |
Correct |
2 ms |
3796 KB |
ans=NO N=2 |
17 |
Incorrect |
2 ms |
3796 KB |
Added cell 17 (1,2) not reachable from infinity |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4948 KB |
ans=NO N=1934 |
2 |
Correct |
7 ms |
4212 KB |
ans=NO N=1965 |
3 |
Incorrect |
10 ms |
4180 KB |
Added cell 1782 (357,253) not reachable from infinity |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3796 KB |
ans=YES N=1 |
2 |
Correct |
2 ms |
3796 KB |
ans=YES N=4 |
3 |
Correct |
2 ms |
3796 KB |
ans=NO N=4 |
4 |
Correct |
2 ms |
3796 KB |
ans=YES N=5 |
5 |
Correct |
2 ms |
3796 KB |
ans=YES N=9 |
6 |
Correct |
3 ms |
3796 KB |
ans=YES N=5 |
7 |
Correct |
2 ms |
3796 KB |
ans=NO N=9 |
8 |
Correct |
2 ms |
3796 KB |
ans=NO N=10 |
9 |
Correct |
2 ms |
3796 KB |
ans=YES N=10 |
10 |
Correct |
2 ms |
3796 KB |
ans=YES N=10 |
11 |
Correct |
2 ms |
3796 KB |
ans=YES N=10 |
12 |
Correct |
3 ms |
3796 KB |
ans=YES N=9 |
13 |
Correct |
2 ms |
3852 KB |
ans=YES N=9 |
14 |
Correct |
2 ms |
3796 KB |
ans=YES N=8 |
15 |
Correct |
2 ms |
3796 KB |
ans=YES N=8 |
16 |
Correct |
2 ms |
3796 KB |
ans=NO N=2 |
17 |
Incorrect |
2 ms |
3796 KB |
Added cell 17 (1,2) not reachable from infinity |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
283 ms |
17572 KB |
ans=NO N=66151 |
2 |
Correct |
278 ms |
33896 KB |
ans=NO N=64333 |
3 |
Incorrect |
363 ms |
17424 KB |
Added cell 69310 (134,-25) not reachable from infinity |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4948 KB |
ans=NO N=1934 |
2 |
Correct |
7 ms |
4212 KB |
ans=NO N=1965 |
3 |
Incorrect |
10 ms |
4180 KB |
Added cell 1782 (357,253) not reachable from infinity |
4 |
Halted |
0 ms |
0 KB |
- |