#include<bits/stdc++.h>
#include "fun.h"
using namespace std;
const int INF = 1e9;
template<class T>bool maximize(T& a, T b){
if(a < b){
a = b;
return true;
}
return false;
}
int n;
namespace sub1{
vector<int>solve(){
vector<vector<int>>d(n, vector<int>(n));
for(int i = 0; i < n; i++){
d[i][i] = 0;
for(int j = i + 1; j < n; j++){
d[i][j] = d[j][i] = hoursRequired(i, j);
}
}
vector<vector<int>>dp(1 << n, vector<int>(n, -INF)), to(1 << n, vector<int>(n));
for(int mask = 1; mask < (1 << n); mask++){
vector<int>p;
for(int i = 0; i < n; i++){
if(1 << i & mask){
p.emplace_back(i);
}
}
if(p.size() == 1){
dp[mask][p[0]] = INF;
continue;
}
for(int& i : p){
for(int& j : p){
if(i != j && d[i][j] <= dp[mask ^ (1 << i)][j] && maximize(dp[mask][i], d[i][j])){
to[mask][i] = j;
}
}
}
}
vector<int>ans;
int state = (1 << n) - 1, i = -1;
for(i = 0; i < n; i++){
if(dp[state][i] > -1){
break;
}
}
for(int _ = 1; _ < n; _++){
ans.emplace_back(i);
int I = to[state][i];
state ^= 1 << i;
i = I;
}
ans.emplace_back(i);
reverse(ans.begin(), ans.end());
return ans;
}
}
namespace sub2{
vector<int>solve(){
vector<vector<int>>g(n);
vector<bool>vis(n, false);
for(int i = 0; i < n; i++){
for(int j = i + 1; j < n; j++){
if(hoursRequired(i, j) == 1){
g[i].emplace_back(j);
g[j].emplace_back(i);
}
}
}
function<pair<int, int>(int, int, int)>dfs;
dfs = [&] (int s, int p, int h){
pair<int, int>ret = make_pair(h, s);
for(int& d : g[s]){
if(d != p && !vis[d]){
maximize(ret, dfs(d, s, h + 1));
}
}
return ret;
};
int u = dfs(1, -1, 0).second;
vector<int>ans = {u};
for(int _ = 1; _ < n; _++){
vis[u] = true;
ans.emplace_back(u = dfs(u, -1, 0).second);
}
return ans;
}
}
vector<int>createFunTour(int __n, int __q){
if((n = __n) <= 17){
return sub2::solve();
}
if(n <= 500){
sub2::solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:98:1: warning: control reaches end of non-void function [-Wreturn-type]
98 | }
| ^
# | 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... |