#include <bits/stdc++.h>
using namespace std;
bool are_connected(vector<int> A, vector<int> B);
vector<int> longest_trip(int N, int D){
vector<vector<int>>graph(N);
for(int i=0;i<N;i++){
for(int j=i+1;j<N;j++){
if(are_connected({i},{j})){
graph[i].push_back(j);
graph[j].push_back(i);
}
}
}
int max_dist=0;
vector<int>ans;
for(int i=0;i<N;i++){
vector<int>dist(N,-1);
vector<int>parent(N,-1);
dist[i]=0;
queue<int>cola;
cola.push(i);
while(!cola.empty()){
int nodo=cola.front();
cola.pop();
for(int vecino:graph[nodo]){
if(dist[vecino]==-1){
parent[vecino]=nodo;
dist[vecino]=(dist[nodo]+1);
cola.push(vecino);
}
}
}
if(*max_element(dist.begin(),dist.end())>max_dist){
max_dist=*max_element(dist.begin(),dist.end());
vector<int>path;
int best_node=max_element(dist.begin(),dist.end())-dist.begin();
while(parent[best_node]!=-1){
path.push_back(best_node);
best_node=parent[best_node];
}
path.push_back(best_node);
ans=path;
}
}
return ans;
}
# |
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 |
6 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 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 |
- |