이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "fun.h"
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k, l) for(int i = (j); i < (k); i += (l))
#define FORD(i, j, k, l) for(int i = (j); i>=(k); i -= (l))
#define REP(i, n) FOR(i, 0, n, 1)
#define REPD(i, n) FORD(i, n, 0, 1)
#define pb push_back
typedef long long ll;
const int INF = (int)1e9;
const ll INFF = (ll)1e18;
std::vector<int> createFunTour(int n, int Q) {
vector<vector<int>> mat(n, vector<int>(n));
REP(i, n){
REP(j, i + 1){
mat[i][j] = mat[j][i] = hoursRequired(i, j);
}
}
vector<int> ans;
vector<vector<int>> g(n);
vector<bool> used(n, false);
REP(i, n){
REP(j, n){
if(mat[i][j] == 1)
g[i].pb(j);
}
}
vector<int> dist(n, -1);
function<void(int, int)> dfs = [&](int v, int p){
if(used[v])
return;
dist[v] = (p == -1 ? 0 : dist[p] + 1);
for(int x : g[v]){
if(x == p) continue;
dfs(x, v);
}
};
dfs(0, -1);
int f = max_element(dist.begin(), dist.end()) - dist.begin();
REP(i, n){
ans.pb(f);
fill(dist.begin(), dist.end(), -1);
dfs(f, -1);
used[f] = true;
f = max_element(dist.begin(), dist.end()) - dist.begin();
}
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... |