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>
using namespace std;
int hoursRequired(int X, int Y);
vector<int> adj[505];
int cur, node;
vector<bool> vis;
void dfs(int v, int p, int d) {
if(d >= cur) node = v, cur = d;
for(auto u : adj[v]) {
if(u == p || vis[u]) continue;
dfs(u, v, d + 1);
}
}
vector<int> createFunTour(int N, int Q) {
vis.assign(N, 0);
for(int l = 0; l < N; l++) {
for(int i = l + 1; i < N; i++) {
int dist = hoursRequired(l, i);
if(dist != 1) continue;
adj[l].push_back(i);
adj[i].push_back(l);
}
}
dfs(0, 0, 0); int st = node; cur = -1;
vector<int> res; res.push_back(st); vis[st] = 1;
while(res.size() < N) {
dfs(st, st, 0); cur = -1;
vis[node] = 1; res.push_back(node);
swap(st, node);
}
return res;
}
Compilation message (stderr)
fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:30:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
30 | while(res.size() < N) {
| ~~~~~~~~~~~^~~
# | 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... |