#include "longesttrip.h"
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
//#define int long long
#define pii pair<int,int>
#define vi vector<int>
#define ff first
#define ss second
#define sp << " " <<
#define all(x) x.begin(),x.end()
#define big(x) ((int)(x.size()))
using namespace std;
const int MOD = 1e9+7, LIM = 1e6+1, inf = 2e9;
std::vector<int> longest_trip(int N, int D)
{
int c[N][N];
for (int i = 0;i<N;i++) {
for (int j = i+1;j<N;j++) {
c[i][j] = c[j][i] = are_connected({i},{j});
}
}
vi ans;
for (int i = 0;i<N;i++) {
deque<int> mytrip;
mytrip.push_back(i);
vi have(N,0);
have[i] = 1;
while (1) {
int fnd = 0;
for (int j = 0;j<N;j++) {
if (have[j]) continue;
if (c[mytrip.front()][j]) mytrip.push_front(j),have[j] = 1,fnd =1;
else if (c[mytrip.back()][j]) mytrip.push_back(j),have[j] = 1,fnd = 1;
}
if (!fnd) break;
}
vi v = vi(all(mytrip));
if (big(v) > big(ans)) ans = v;
}
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... |