#include <bits/stdc++.h>
using namespace std;
int dl[]={1,1,1,0,0,-1,-1,-1};
int dc[]={-1,0,1,-1,1,1,-1,0};
int dl2[]={1,0,0,-1};
int dc2[]={0,1,-1,0};
int n,t,i,sol[150005],nr,fr[150005],j,k;
pair <int,int> loc,b;
queue <int> q;
struct wow
{
int x,y;
}v[150005];
int main()
{
#ifdef HOME
ifstream cin("date.in");
ofstream cout("date.out");
#endif // HOME
cin>>n;
cin>>t;
for (i=1;i<=n;i++)
{
cin>>v[i].x>>v[i].y;
}
if (t==1)
{
q.push(1);
sol[++nr]=1;
fr[1]=1;
while (!q.empty())
{
loc={v[q.front()].x,v[q.front()].y};
q.pop();
for (i=0;i<4;i++)
{
b.first=loc.first+dl2[i];
b.second=loc.second+dc2[i];
for (j=1;j<=n;j++)
{
if (b.first==v[j].x&&b.second==v[j].y&&fr[j]==0)
{
sol[++nr]=j;
fr[j]=1;
q.push(j);
}
}
}
}
for (j=1;j<=n;j++)
{
if (fr[j]==0)
{
for (i=0;i<8;i++)
{
b.first=v[j].x+dl[i];
b.second=v[j].y+dc[i];
for (k=1;k<=n;k++)
{
if (b.first==v[k].x&&b.second==v[k].y&&fr[k]==0)
{
sol[++nr]=k;
fr[k]=1;
q.push(k);
}
}
}
}
}
while (!q.empty())
{
loc={v[q.front()].x,v[q.front()].y};
q.pop();
for (i=0;i<8;i++)
{
b.first=loc.first+dl[i];
b.second=loc.second+dc[i];
for (j=1;j<=n;j++)
{
if (b.first==v[j].x&&b.second==v[j].y&&fr[j]==0)
{
sol[++nr]=j;
fr[j]=1;
q.push(j);
}
}
}
}
for (i=1;i<=n;i++)
{
if (fr[i]==0)
{
cout<<"NO";
return 0;
}
}
cout<<"YES"<<'\n';
for (i=1;i<=n;i++)
{
cout<<sol[i]<<'\n';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
384 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
384 KB |
ans=NO N=4 |
4 |
Incorrect |
1 ms |
384 KB |
Contestant did not find solution |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
384 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
384 KB |
ans=NO N=4 |
4 |
Incorrect |
1 ms |
384 KB |
Contestant did not find solution |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
384 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
384 KB |
ans=NO N=4 |
4 |
Incorrect |
1 ms |
384 KB |
Contestant did not find solution |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
384 KB |
Unexpected end of file - token expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
384 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
384 KB |
ans=NO N=4 |
4 |
Incorrect |
1 ms |
384 KB |
Contestant did not find solution |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
44 ms |
764 KB |
Unexpected end of file - token expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
384 KB |
Unexpected end of file - token expected |
2 |
Halted |
0 ms |
0 KB |
- |