#include <vector>
#include "longesttrip.h"
using namespace std;
vector<vector<int>> adj;
vector<bool> visited;
vector<int> current_path, best_path;
void dfs(int u) {
visited[u] = true;
current_path.push_back(u);
if (current_path.size() > best_path.size()) {
best_path = current_path;
}
for (int v : adj[u]) {
if (!visited[v]) {
dfs(v);
}
}
visited[u] = false;
current_path.pop_back();
}
vector<int> longest_trip(int N, int D) {
adj = vector<vector<int>>(N);
visited = vector<bool>(N, false);
best_path.clear();
for (int u = 0; u < N; ++u) {
for (int v = u + 1; v < N; ++v) {
vector<int> A = {u}, B = {v};
if (are_connected(A, B)) {
adj[u].push_back(v);
adj[v].push_back(u);
}
}
}
for (int i = 0; i < N; ++i) {
current_path.clear();
dfs(i);
}
return best_path;
}
# | 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... |