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>
#include "fun.h"
#define MAXN 100007
using namespace std;
int n,centroid,sz[MAXN],dist[MAXN],curr;
vector< vector< pair<int,int> > > subtrees;
int best,last;
vector<int> perm;
bool cmp(vector< pair<int,int> > fr,vector< pair<int,int> > sc){
return fr.size()<sc.size();
}
vector<int> createFunTour(int N, int Q){
n=N;
for(int i=0;i<n;i++){
sz[i]=attractionsBehind(0,i);
if(sz[i]>n/2 and sz[i]<sz[centroid])centroid=i;
}
for(int i=0;i<n;i++){
dist[i]=hoursRequired(centroid,i);
if(dist[i]==1)subtrees.push_back({{1,i}});
}
for(int i=0;i<n;i++){
if(dist[i]<=1)continue;
for(int f=0;f<subtrees.size();f++){
if(f==subtrees.size()-1){
subtrees.back().push_back({dist[i],i});
break;
}
curr=hoursRequired(subtrees[f][0].second,i);
if(curr+1==dist[i]){
subtrees[f].push_back({dist[i],i});
break;
}
}
}
for(int i=0;i<subtrees.size();i++){
sort(subtrees[i].begin(),subtrees[i].end());
}
last=-1;
for(int i=0;i<n-1;i++){
int maxs=0,sum=0;
for(int f=0;f<subtrees.size();f++){
maxs=max(maxs,int(subtrees[f].size()));
sum+=subtrees[f].size();
}
sort(subtrees.begin(),subtrees.end(),cmp);
if(subtrees.size()==3 and maxs*2==sum){
sort(subtrees.begin(),subtrees.end(),cmp);
for(pair<int,int> i:subtrees[1])subtrees[0].push_back(i);
sort(subtrees[0].begin(),subtrees[0].end());
if(!subtrees[1].empty() and last==subtrees[1][0].second){
last=subtrees[0][0].second;
}
subtrees[1]=subtrees[2];
subtrees.pop_back();
}
int best=-1;
for(int f=0;f<subtrees.size();f++){
if(subtrees[f].empty() or last==subtrees[f][0].second)continue;
if(best==-1 or subtrees[f].back().first>subtrees[best].back().first)best=f;
if(subtrees[f].back().first==subtrees[best].back().first and subtrees[f].size()>subtrees[best].size())best=f;
}
perm.push_back(subtrees[best].back().second);
last=subtrees[best][0].second;
subtrees[best].pop_back();
}
perm.push_back(centroid);
return perm;
}
Compilation message (stderr)
fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:32:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for(int f=0;f<subtrees.size();f++){
| ~^~~~~~~~~~~~~~~~
fun.cpp:33:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | if(f==subtrees.size()-1){
| ~^~~~~~~~~~~~~~~~~~~
fun.cpp:46:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i=0;i<subtrees.size();i++){
| ~^~~~~~~~~~~~~~~~
fun.cpp:56:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int f=0;f<subtrees.size();f++){
| ~^~~~~~~~~~~~~~~~
fun.cpp:78:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for(int f=0;f<subtrees.size();f++){
| ~^~~~~~~~~~~~~~~~
# | 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... |