#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 |
1 |
Incorrect |
0 ms |
344 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
344 KB |
Incorrect |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |