#include <bits/stdc++.h>
#include "longesttrip.h"
using namespace std;
vector<vector<int>> neigh;
vector<bool> visited;
vector<int> longest_path(int i){
if(visited[i]) return {};
visited[i]=true;
vector<int> longest_vector;
for (int c : neigh[i])
{
vector<int> c_longest=longest_path(c);
if(c_longest.size()>longest_vector.size()) longest_vector=c_longest;
}
longest_vector.push_back(i);
return longest_vector;
}
std::vector<int> longest_trip(int N, int D)
{
vector<int> ret;
neigh.clear();
neigh.resize(N);
for (int i = 0; i < N-1; i++){
for (int j = i+1; j < N; j++)
{
if(are_connected({i}, {j})){
neigh[i].push_back(j);
neigh[j].push_back(i);
}
}
}
vector<int> longest_vector;
for (int i = 0; i < N; i++){
visited.clear();
visited.resize(N);
vector<int> c_longest=longest_path(i);
if(c_longest.size()>longest_vector.size()) longest_vector=c_longest;
}
return longest_vector;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
237 ms |
1532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
25 ms |
344 KB |
Output is correct |
3 |
Correct |
138 ms |
696 KB |
Output is correct |
4 |
Correct |
452 ms |
764 KB |
Output is correct |
5 |
Execution timed out |
1028 ms |
1576 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
23 ms |
344 KB |
Output is correct |
3 |
Correct |
120 ms |
952 KB |
Output is correct |
4 |
Correct |
416 ms |
1124 KB |
Output is correct |
5 |
Correct |
987 ms |
1380 KB |
Output is correct |
6 |
Correct |
6 ms |
344 KB |
Output is correct |
7 |
Correct |
25 ms |
344 KB |
Output is correct |
8 |
Correct |
141 ms |
1112 KB |
Output is correct |
9 |
Correct |
328 ms |
1112 KB |
Output is correct |
10 |
Execution timed out |
1041 ms |
1536 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
340 KB |
Output is correct |
2 |
Correct |
23 ms |
344 KB |
Output is correct |
3 |
Correct |
134 ms |
856 KB |
Output is correct |
4 |
Correct |
482 ms |
748 KB |
Output is correct |
5 |
Execution timed out |
1045 ms |
1124 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
344 KB |
Output is correct |
2 |
Correct |
23 ms |
344 KB |
Output is correct |
3 |
Partially correct |
141 ms |
1112 KB |
Output is partially correct |
4 |
Partially correct |
442 ms |
1048 KB |
Output is partially correct |
5 |
Execution timed out |
1059 ms |
1572 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |