#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;
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);
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
198 ms |
1228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
25 ms |
344 KB |
Output is correct |
3 |
Correct |
174 ms |
452 KB |
Output is correct |
4 |
Correct |
447 ms |
696 KB |
Output is correct |
5 |
Correct |
867 ms |
1032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
344 KB |
Output is correct |
2 |
Correct |
26 ms |
344 KB |
Output is correct |
3 |
Correct |
157 ms |
344 KB |
Output is correct |
4 |
Correct |
471 ms |
752 KB |
Output is correct |
5 |
Correct |
920 ms |
888 KB |
Output is correct |
6 |
Correct |
10 ms |
344 KB |
Output is correct |
7 |
Correct |
23 ms |
344 KB |
Output is correct |
8 |
Correct |
176 ms |
600 KB |
Output is correct |
9 |
Correct |
361 ms |
740 KB |
Output is correct |
10 |
Correct |
837 ms |
1000 KB |
Output is correct |
11 |
Correct |
892 ms |
812 KB |
Output is correct |
12 |
Correct |
944 ms |
1500 KB |
Output is correct |
13 |
Correct |
922 ms |
1136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
344 KB |
Output is correct |
2 |
Correct |
21 ms |
344 KB |
Output is correct |
3 |
Correct |
170 ms |
344 KB |
Output is correct |
4 |
Correct |
434 ms |
748 KB |
Output is correct |
5 |
Correct |
913 ms |
740 KB |
Output is correct |
6 |
Correct |
7 ms |
344 KB |
Output is correct |
7 |
Correct |
28 ms |
344 KB |
Output is correct |
8 |
Correct |
156 ms |
600 KB |
Output is correct |
9 |
Correct |
318 ms |
720 KB |
Output is correct |
10 |
Correct |
910 ms |
724 KB |
Output is correct |
11 |
Correct |
938 ms |
844 KB |
Output is correct |
12 |
Correct |
867 ms |
776 KB |
Output is correct |
13 |
Correct |
822 ms |
740 KB |
Output is correct |
14 |
Correct |
9 ms |
344 KB |
Output is correct |
15 |
Correct |
13 ms |
344 KB |
Output is correct |
16 |
Correct |
69 ms |
344 KB |
Output is correct |
17 |
Correct |
102 ms |
420 KB |
Output is correct |
18 |
Correct |
168 ms |
608 KB |
Output is correct |
19 |
Correct |
319 ms |
648 KB |
Output is correct |
20 |
Correct |
368 ms |
964 KB |
Output is correct |
21 |
Correct |
945 ms |
1132 KB |
Output is correct |
22 |
Correct |
997 ms |
996 KB |
Output is correct |
23 |
Correct |
892 ms |
1772 KB |
Output is correct |
24 |
Correct |
912 ms |
1416 KB |
Output is correct |
25 |
Correct |
7 ms |
344 KB |
Output is correct |
26 |
Correct |
9 ms |
344 KB |
Output is correct |
27 |
Correct |
18 ms |
344 KB |
Output is correct |
28 |
Correct |
23 ms |
344 KB |
Output is correct |
29 |
Correct |
34 ms |
344 KB |
Output is correct |
30 |
Correct |
195 ms |
600 KB |
Output is correct |
31 |
Correct |
197 ms |
452 KB |
Output is correct |
32 |
Correct |
200 ms |
600 KB |
Output is correct |
33 |
Correct |
295 ms |
724 KB |
Output is correct |
34 |
Correct |
381 ms |
612 KB |
Output is correct |
35 |
Correct |
375 ms |
844 KB |
Output is correct |
36 |
Correct |
964 ms |
1224 KB |
Output is correct |
37 |
Correct |
978 ms |
784 KB |
Output is correct |
38 |
Correct |
902 ms |
1088 KB |
Output is correct |
39 |
Correct |
799 ms |
900 KB |
Output is correct |
40 |
Correct |
848 ms |
1044 KB |
Output is correct |
41 |
Correct |
879 ms |
820 KB |
Output is correct |
42 |
Correct |
930 ms |
740 KB |
Output is correct |
43 |
Correct |
902 ms |
1160 KB |
Output is correct |
44 |
Correct |
828 ms |
1036 KB |
Output is correct |
45 |
Correct |
9 ms |
344 KB |
Output is correct |
46 |
Correct |
10 ms |
344 KB |
Output is correct |
47 |
Correct |
22 ms |
344 KB |
Output is correct |
48 |
Correct |
22 ms |
344 KB |
Output is correct |
49 |
Correct |
23 ms |
512 KB |
Output is correct |
50 |
Correct |
213 ms |
440 KB |
Output is correct |
51 |
Correct |
204 ms |
600 KB |
Output is correct |
52 |
Correct |
185 ms |
592 KB |
Output is correct |
53 |
Correct |
305 ms |
492 KB |
Output is correct |
54 |
Correct |
299 ms |
600 KB |
Output is correct |
55 |
Correct |
324 ms |
484 KB |
Output is correct |
56 |
Correct |
816 ms |
972 KB |
Output is correct |
57 |
Correct |
885 ms |
696 KB |
Output is correct |
58 |
Correct |
827 ms |
1084 KB |
Output is correct |
59 |
Correct |
848 ms |
792 KB |
Output is correct |
60 |
Correct |
849 ms |
1224 KB |
Output is correct |
61 |
Correct |
881 ms |
700 KB |
Output is correct |
62 |
Correct |
777 ms |
720 KB |
Output is correct |
63 |
Correct |
768 ms |
1036 KB |
Output is correct |
64 |
Correct |
823 ms |
872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
340 KB |
Output is correct |
2 |
Correct |
32 ms |
344 KB |
Output is correct |
3 |
Partially correct |
144 ms |
456 KB |
Output is partially correct |
4 |
Partially correct |
431 ms |
936 KB |
Output is partially correct |
5 |
Partially correct |
873 ms |
704 KB |
Output is partially correct |
6 |
Correct |
8 ms |
344 KB |
Output is correct |
7 |
Correct |
28 ms |
344 KB |
Output is correct |
8 |
Partially correct |
167 ms |
344 KB |
Output is partially correct |
9 |
Partially correct |
339 ms |
344 KB |
Output is partially correct |
10 |
Partially correct |
887 ms |
828 KB |
Output is partially correct |
11 |
Partially correct |
885 ms |
892 KB |
Output is partially correct |
12 |
Partially correct |
934 ms |
976 KB |
Output is partially correct |
13 |
Partially correct |
882 ms |
1228 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 |
8 ms |
344 KB |
Incorrect |
17 |
Halted |
0 ms |
0 KB |
- |