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 "longesttrip.h"
#include<bits/stdc++.h>
using namespace std;
int ans = 0;
vector<int> ord;
int vis[200005];
vector<int> adj[200005];
void dfs(int i, int d, vector<int> proc) {
if (vis[i]) {
return;
}
vis[i] = 1;
proc.push_back(i);
if (d > ans) {
d = ans;
ord = proc;
}
for (int j : adj[i]) {
dfs(j, d+1, proc);
}
proc.pop_back();
vis[i] = 0;
}
vector<int> longest_trip(int n, int d) {
for (int i = 0; i < n; i++) {
adj[i].clear();
}
for (int i = 0; i < n; i++) {
for (int j = i+1; j < n; j++) {
if (are_connected({i}, {j})) {
adj[i].push_back(j);
adj[j].push_back(i);
}
}
}
ans = 0;
ord.clear();
for (int i = 0; i < n; i++) {
dfs(i, 0, {});
}
return ord;
}
# | 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... |