# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
898366 | irmuun | Fun Tour (APIO20_fun) | C++17 | 23 ms | 1372 KiB |
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"
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
const int maxN=5e2;
vector<int>adj[maxN];
int dist[maxN][maxN],root=0,d=0;
void dfs(int x,int p){
dist[root][x]=d;
for(auto y:adj[x]){
if(y!=p){
d++;
dfs(y,x);
}
}
d--;
};
vector<int>createFunTour(int N,int Q){
if(N<=500){
for(int i=0;i<N;i++){
for(int j=i+1;j<N;j++){
if(hoursRequired(i,j)==1){
adj[i].pb(j);
adj[j].pb(i);
}
}
}
for(int i=0;i<N;i++){
root=i;
d=0;
dfs(i,-1);
}
int cur=0,mx=0;
for(ll i=0;i<N;i++){
if(dist[0][i]>mx){
mx=dist[0][i];
cur=i;
}
}
vector<int>ans;
vector<bool>used(N,0);
while(ans.size()<N){
ans.pb(cur);
used[cur]=true;
mx=-1;
int nxt=0;
for(int i=0;i<N;i++){
if(!used[i]&&dist[cur][i]>mx){
mx=dist[cur][i];
nxt=i;
}
}
cur=nxt;
}
return ans;
}
}
Compilation message (stderr)
# | 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... |