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 <bits/stdc++.h>
#include "longesttrip.h"
using namespace std;
const int nmax = 256;
int n;
std::vector<int> G[nmax + 5];
vector<int> r;
int d[nmax + 5];
void bfs(int nod)
{
queue<int> q;
for(int i=0;i<n;i++)
{
d[i] = 0;
}
d[nod] = 1;
q.push(nod);
while(!q.empty())
{
nod = q.front();
q.pop();
for(auto it : G[nod])
{
if(d[it])
{
continue;
}
d[it] = 1 + d[nod];
q.push(it);
}
}
for(int i=0;i<n;i++)
{
if(d[i] > d[nod])
{
nod = i;
}
}
vector<int> aux;
aux.push_back(nod);
while(d[nod]!=1)
{
for(auto it : G[nod])
{
if(d[it]==d[nod] - 1)
{
nod = it;
break;
}
}
aux.push_back(nod);
}
if(aux.size() > r.size())
{
r = aux;
}
}
std::vector<int> longest_trip(int N, int D)
{
n = N;
r.clear();
for(int i=0;i<n;i++)
{
G[i].clear();
}
for(int i=0; i<n; i++)
{
for(int j=i+1; j<n; j++)
{
if(are_connected({i}, {j}))
{
G[i].push_back(j);
G[j].push_back(i);
}
}
}
for(int i=0;i<n;i++)
{
bfs(i);
}
return r;
}
# | 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... |