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 "fun.h"
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
const int N=200005;
int cntid=0;
const int INF=1e9;
vector<int> adj[N],sz(N,1),pa(N),ans,dis(N);
priority_queue<pair<int,int>> pq[3];
void dfs(int k){
for(int j:adj[k]){
if(j==pa[k])continue;
pa[j]=k;
dfs(j);
sz[k]+=sz[j];
}
}
int cen(int k,int need){
for(int j:adj[k]){
if(j==pa[k])continue;
if(sz[j]>=need)return cen(j,need);
}
return k;
}
void dfs1(int k,int pa){
pq[cntid].push({dis[k],k});
for(int j:adj[k]){
if(j==pa)continue;
dis[j]=dis[k]+1;
dfs1(j,k);
}
}
vector<int> createFunTour(int n, int q) {
//int H = hoursRequired(0, N - 1);
//int A = attractionsBehind(0, N - 1);
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(hoursRequired(i,j)==1){
adj[i].push_back(j);
adj[j].push_back(i);
}
}
}
dfs(0);
int c1=0;
int need=(n+1)/2;
int mn=INF;
for(int i=1;i<n;i++){
int t=attractionsBehind(0, i);
if(t>=need&&t<mn){
mn=t;
c1=i;
}
}
for(int j:adj[c1]){
dfs1(j,c1);
cntid++;
}
int last=-1;
for(int i=1;i<n;i++){
pair<int,int> p={-1,-1};
for(int j=0;j<cntid;j++){
if(j==last||pq[j].size()==0)continue;
p=max(p,make_pair(pq[j].top().first,j));
}
last=p.second;
auto [dis1,idx]=pq[p.second].top();
pq[p.second].pop();
ans.push_back(idx);
}
ans.push_back(c1);
/*for(int j:ans){
cout<<j<<' ';
}
cout<<endl;*/
return ans;
}
# | 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... |