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>
#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;
b.erase(b.begin());
while(cnt!=n)
{
for(int i=0;i<b.size();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;
b.erase(b.begin()+i);
break;
}
}
}
}
}
return 0;
}
Compilation message (stderr)
skyscrapers.cpp: In function 'int main()':
skyscrapers.cpp:65:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int i=0;i<b.size();i++)
| ~^~~~~~~~~
# | 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... |