# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1069814 | Muhammad_Aneeq | Longest Trip (IOI23_longesttrip) | C++17 | 926 ms | 1620 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O2")
#include <vector>
#include <set>
#include "longesttrip.h"
using namespace std;
int const MAXN=256;
vector<int>nei[MAXN]={};
vector<int>ans;
vector<int>cur;
bool vis[MAXN]={};
void dfs(int u,int p=-1)
{
vis[u]=1;
cur.push_back(u);
bool w=0;
for (auto i:nei[u])
{
if (vis[i])
continue;
w=1;
dfs(i,u);
}
if (cur.size()>ans.size())
ans=cur;
cur.pop_back();
}
vector<int> sol(int N)
{
for (int i=0;i<N;i++)
{
if (!vis[i])
dfs(i);
}
return ans;
}
vector<int> longest_trip(int N, int D)
{
ans={};
cur={};
for (int i=0;i<N;i++)
nei[i]={},vis[i]=0;
for (int i=0;i<N;i++)
for (int j=i+1;j<N;j++)
if (are_connected({i},{j}))
nei[i].push_back(j),nei[j].push_back(i);
if (D==1)
{
return sol(N);
}
for (int i=0;i<N;i++)
{
for (int j=0;j<N;j++)
vis[j]=0;
dfs(i);
}
return ans;
}
Compilation message (stderr)
# | 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... |