#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,vector<int>());
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;
stack<int>cola;
cola.push(i);
while(!cola.empty()){
int nodo=cola.top();
cola.pop();
for(int vecino:graph[nodo]){
if(dist[vecino]==-1){
parent[vecino]=nodo;
dist[vecino]=(dist[nodo]+1);
cola.push(vecino);
break;
}
}
}
if(*max_element(dist.begin(),dist.end())>max_dist){
max_dist=*max_element(dist.begin(),dist.end());
vector<int>path;
int best_node;
for(int j=0;j<N;j++){
if(dist[j]==max_dist){
best_node=j;
}
}
path.push_back(best_node);
while(parent[best_node]!=-1){
best_node=parent[best_node];
path.push_back(best_node);
}
ans=path;
}
}
reverse(ans.begin(),ans.end());
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
207 ms |
1156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
23 ms |
344 KB |
Output is correct |
3 |
Correct |
140 ms |
344 KB |
Output is correct |
4 |
Correct |
403 ms |
1008 KB |
Output is correct |
5 |
Correct |
880 ms |
996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
344 KB |
Output is correct |
2 |
Correct |
16 ms |
344 KB |
Output is correct |
3 |
Correct |
150 ms |
344 KB |
Output is correct |
4 |
Correct |
403 ms |
596 KB |
Output is correct |
5 |
Correct |
861 ms |
964 KB |
Output is correct |
6 |
Correct |
8 ms |
344 KB |
Output is correct |
7 |
Correct |
23 ms |
344 KB |
Output is correct |
8 |
Correct |
138 ms |
456 KB |
Output is correct |
9 |
Correct |
342 ms |
600 KB |
Output is correct |
10 |
Correct |
854 ms |
720 KB |
Output is correct |
11 |
Correct |
893 ms |
988 KB |
Output is correct |
12 |
Correct |
847 ms |
1236 KB |
Output is correct |
13 |
Correct |
870 ms |
856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
596 KB |
Output is correct |
2 |
Correct |
19 ms |
344 KB |
Output is correct |
3 |
Correct |
168 ms |
344 KB |
Output is correct |
4 |
Correct |
410 ms |
852 KB |
Output is correct |
5 |
Correct |
857 ms |
888 KB |
Output is correct |
6 |
Correct |
5 ms |
344 KB |
Output is correct |
7 |
Correct |
20 ms |
344 KB |
Output is correct |
8 |
Correct |
154 ms |
600 KB |
Output is correct |
9 |
Correct |
316 ms |
344 KB |
Output is correct |
10 |
Correct |
904 ms |
716 KB |
Output is correct |
11 |
Correct |
888 ms |
792 KB |
Output is correct |
12 |
Correct |
867 ms |
964 KB |
Output is correct |
13 |
Correct |
807 ms |
880 KB |
Output is correct |
14 |
Correct |
7 ms |
344 KB |
Output is correct |
15 |
Correct |
11 ms |
344 KB |
Output is correct |
16 |
Correct |
35 ms |
344 KB |
Output is correct |
17 |
Correct |
108 ms |
344 KB |
Output is correct |
18 |
Correct |
173 ms |
344 KB |
Output is correct |
19 |
Correct |
351 ms |
600 KB |
Output is correct |
20 |
Correct |
315 ms |
504 KB |
Output is correct |
21 |
Correct |
924 ms |
1108 KB |
Output is correct |
22 |
Correct |
866 ms |
924 KB |
Output is correct |
23 |
Correct |
869 ms |
1152 KB |
Output is correct |
24 |
Correct |
893 ms |
824 KB |
Output is correct |
25 |
Correct |
12 ms |
344 KB |
Output is correct |
26 |
Correct |
12 ms |
344 KB |
Output is correct |
27 |
Correct |
30 ms |
344 KB |
Output is correct |
28 |
Correct |
33 ms |
340 KB |
Output is correct |
29 |
Correct |
31 ms |
344 KB |
Output is correct |
30 |
Correct |
216 ms |
444 KB |
Output is correct |
31 |
Correct |
204 ms |
340 KB |
Output is correct |
32 |
Correct |
228 ms |
344 KB |
Output is correct |
33 |
Correct |
335 ms |
488 KB |
Output is correct |
34 |
Correct |
300 ms |
724 KB |
Output is correct |
35 |
Correct |
329 ms |
856 KB |
Output is correct |
36 |
Correct |
950 ms |
1048 KB |
Output is correct |
37 |
Correct |
871 ms |
956 KB |
Output is correct |
38 |
Correct |
906 ms |
672 KB |
Output is correct |
39 |
Correct |
813 ms |
1036 KB |
Output is correct |
40 |
Correct |
876 ms |
956 KB |
Output is correct |
41 |
Correct |
846 ms |
1268 KB |
Output is correct |
42 |
Correct |
896 ms |
724 KB |
Output is correct |
43 |
Correct |
816 ms |
764 KB |
Output is correct |
44 |
Correct |
853 ms |
1124 KB |
Output is correct |
45 |
Correct |
13 ms |
344 KB |
Output is correct |
46 |
Correct |
14 ms |
344 KB |
Output is correct |
47 |
Correct |
33 ms |
596 KB |
Output is correct |
48 |
Correct |
26 ms |
340 KB |
Output is correct |
49 |
Correct |
31 ms |
344 KB |
Output is correct |
50 |
Correct |
232 ms |
600 KB |
Output is correct |
51 |
Correct |
211 ms |
448 KB |
Output is correct |
52 |
Correct |
209 ms |
436 KB |
Output is correct |
53 |
Correct |
312 ms |
600 KB |
Output is correct |
54 |
Correct |
361 ms |
732 KB |
Output is correct |
55 |
Correct |
338 ms |
496 KB |
Output is correct |
56 |
Correct |
901 ms |
1104 KB |
Output is correct |
57 |
Correct |
918 ms |
1124 KB |
Output is correct |
58 |
Correct |
870 ms |
1196 KB |
Output is correct |
59 |
Correct |
876 ms |
1096 KB |
Output is correct |
60 |
Correct |
766 ms |
1088 KB |
Output is correct |
61 |
Correct |
818 ms |
772 KB |
Output is correct |
62 |
Correct |
905 ms |
780 KB |
Output is correct |
63 |
Correct |
956 ms |
1024 KB |
Output is correct |
64 |
Correct |
884 ms |
748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
344 KB |
Output is correct |
2 |
Correct |
32 ms |
344 KB |
Output is correct |
3 |
Partially correct |
179 ms |
344 KB |
Output is partially correct |
4 |
Partially correct |
457 ms |
748 KB |
Output is partially correct |
5 |
Partially correct |
883 ms |
852 KB |
Output is partially correct |
6 |
Correct |
6 ms |
344 KB |
Output is correct |
7 |
Correct |
31 ms |
344 KB |
Output is correct |
8 |
Partially correct |
172 ms |
344 KB |
Output is partially correct |
9 |
Partially correct |
325 ms |
988 KB |
Output is partially correct |
10 |
Partially correct |
881 ms |
980 KB |
Output is partially correct |
11 |
Partially correct |
900 ms |
1340 KB |
Output is partially correct |
12 |
Partially correct |
968 ms |
1384 KB |
Output is partially correct |
13 |
Partially correct |
958 ms |
1196 KB |
Output is partially correct |
14 |
Correct |
7 ms |
344 KB |
Output is correct |
15 |
Correct |
10 ms |
344 KB |
Output is correct |
16 |
Incorrect |
7 ms |
344 KB |
Incorrect |
17 |
Halted |
0 ms |
0 KB |
- |