#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
int mxlen = INT_MIN;
vector<int> ans;
void dfs(vector<int> adj[], int node, int cnt, vector<int> &vis, vector<int> temp)
{
vis[node] = 1;
int cur = 0;
for (int a : adj[node])
{
if (!vis[a])
{
cur = cnt + 1;
temp.push_back(a);
dfs(adj, a, cur, vis, temp);
}
if (mxlen < cur)
mxlen = cur;
ans.clear();
ans = temp;
temp.pop_back();
cur = 0;
}
}
vector<int> longest_trip(int n, int d)
{
vector<int> adj[n];
for (int i = 0; i < n - 1; i++)
{
for (int j = i+1; j < n; j++)
{
if (are_connected({i}, {j}))
{
adj[i].push_back(j);
adj[j].push_back(i);
}
}
}
vector<int> vis, temp;
for(int i=0;i<n;i++)
{
vis.clear();
temp.clear();
vis.resize(n, 0);
temp.push_back(i);
dfs(adj, i, 0, vis, temp);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |