#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> longest_trip(int N,int D){
vector<vector<int>> adj(N);
for(int i=0;i<N;i++) {
for(int j=i+1;j<N;j++) {
if(are_connected({i},{j})) {
adj[i].emplace_back(j);
adj[j].emplace_back(i);
}
}
}
int ans = 0;
for(int i=0;i<N;i++) {
vector<bool> visited(N);
function<void(int,int)> dfs = [&](int x,int depth) {
visited[x]=true;
ans=max(ans,depth);
for(int&v:adj[x])if(!visited[v])dfs(v,depth+1);
};
dfs(i,0);
}
vector<int> full;
for(int i=0;i<N;i++) {
stack<int> path;
vector<bool> visited(N);
function<void(int,int)> dfs = [&](int x,int depth) {
visited[x]=true;
path.emplace(x);
if(ans==depth) {
while(!path.empty()) {
full.emplace_back(path.top());
path.pop();
}
}
for(int&v:adj[x])if(!visited[v]) {
dfs(v,depth+1);
if(!full.empty())return;
}
path.pop();
};
dfs(i,0);
if(!full.empty())return full;
}
}
Compilation message
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:6:30: warning: control reaches end of non-void function [-Wreturn-type]
6 | vector<vector<int>> adj(N);
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
207 ms |
984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
29 ms |
344 KB |
Output is correct |
3 |
Correct |
138 ms |
344 KB |
Output is correct |
4 |
Correct |
414 ms |
740 KB |
Output is correct |
5 |
Correct |
978 ms |
980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
22 ms |
344 KB |
Output is correct |
3 |
Correct |
151 ms |
344 KB |
Output is correct |
4 |
Correct |
462 ms |
504 KB |
Output is correct |
5 |
Correct |
922 ms |
996 KB |
Output is correct |
6 |
Correct |
5 ms |
344 KB |
Output is correct |
7 |
Correct |
23 ms |
344 KB |
Output is correct |
8 |
Correct |
174 ms |
344 KB |
Output is correct |
9 |
Correct |
318 ms |
728 KB |
Output is correct |
10 |
Correct |
905 ms |
1096 KB |
Output is correct |
11 |
Correct |
949 ms |
1068 KB |
Output is correct |
12 |
Correct |
956 ms |
992 KB |
Output is correct |
13 |
Correct |
944 ms |
924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
21 ms |
344 KB |
Output is correct |
3 |
Correct |
166 ms |
600 KB |
Output is correct |
4 |
Correct |
450 ms |
716 KB |
Output is correct |
5 |
Correct |
936 ms |
1008 KB |
Output is correct |
6 |
Correct |
8 ms |
344 KB |
Output is correct |
7 |
Correct |
30 ms |
344 KB |
Output is correct |
8 |
Correct |
180 ms |
456 KB |
Output is correct |
9 |
Correct |
313 ms |
460 KB |
Output is correct |
10 |
Correct |
979 ms |
980 KB |
Output is correct |
11 |
Correct |
907 ms |
1048 KB |
Output is correct |
12 |
Correct |
926 ms |
792 KB |
Output is correct |
13 |
Correct |
943 ms |
1252 KB |
Output is correct |
14 |
Correct |
6 ms |
344 KB |
Output is correct |
15 |
Correct |
12 ms |
344 KB |
Output is correct |
16 |
Correct |
42 ms |
344 KB |
Output is correct |
17 |
Correct |
103 ms |
344 KB |
Output is correct |
18 |
Correct |
160 ms |
344 KB |
Output is correct |
19 |
Correct |
316 ms |
732 KB |
Output is correct |
20 |
Correct |
319 ms |
848 KB |
Output is correct |
21 |
Correct |
964 ms |
1128 KB |
Output is correct |
22 |
Correct |
888 ms |
900 KB |
Output is correct |
23 |
Correct |
922 ms |
1324 KB |
Output is correct |
24 |
Correct |
966 ms |
1272 KB |
Output is correct |
25 |
Correct |
9 ms |
344 KB |
Output is correct |
26 |
Correct |
9 ms |
344 KB |
Output is correct |
27 |
Correct |
29 ms |
344 KB |
Output is correct |
28 |
Correct |
16 ms |
340 KB |
Output is correct |
29 |
Correct |
22 ms |
344 KB |
Output is correct |
30 |
Correct |
212 ms |
460 KB |
Output is correct |
31 |
Correct |
201 ms |
444 KB |
Output is correct |
32 |
Correct |
220 ms |
344 KB |
Output is correct |
33 |
Correct |
301 ms |
600 KB |
Output is correct |
34 |
Correct |
347 ms |
464 KB |
Output is correct |
35 |
Correct |
334 ms |
480 KB |
Output is correct |
36 |
Correct |
977 ms |
1008 KB |
Output is correct |
37 |
Correct |
968 ms |
972 KB |
Output is correct |
38 |
Correct |
883 ms |
1212 KB |
Output is correct |
39 |
Correct |
910 ms |
928 KB |
Output is correct |
40 |
Correct |
883 ms |
1060 KB |
Output is correct |
41 |
Correct |
908 ms |
840 KB |
Output is correct |
42 |
Correct |
870 ms |
836 KB |
Output is correct |
43 |
Correct |
864 ms |
1136 KB |
Output is correct |
44 |
Correct |
854 ms |
1076 KB |
Output is correct |
45 |
Correct |
10 ms |
344 KB |
Output is correct |
46 |
Correct |
9 ms |
344 KB |
Output is correct |
47 |
Correct |
30 ms |
344 KB |
Output is correct |
48 |
Correct |
18 ms |
344 KB |
Output is correct |
49 |
Correct |
27 ms |
344 KB |
Output is correct |
50 |
Correct |
214 ms |
440 KB |
Output is correct |
51 |
Correct |
235 ms |
680 KB |
Output is correct |
52 |
Correct |
223 ms |
344 KB |
Output is correct |
53 |
Correct |
338 ms |
736 KB |
Output is correct |
54 |
Correct |
316 ms |
484 KB |
Output is correct |
55 |
Correct |
321 ms |
736 KB |
Output is correct |
56 |
Execution timed out |
1004 ms |
972 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
344 KB |
Output is correct |
2 |
Correct |
19 ms |
344 KB |
Output is correct |
3 |
Partially correct |
133 ms |
344 KB |
Output is partially correct |
4 |
Partially correct |
442 ms |
600 KB |
Output is partially correct |
5 |
Partially correct |
888 ms |
1212 KB |
Output is partially correct |
6 |
Correct |
7 ms |
344 KB |
Output is correct |
7 |
Correct |
20 ms |
344 KB |
Output is correct |
8 |
Partially correct |
148 ms |
448 KB |
Output is partially correct |
9 |
Partially correct |
310 ms |
968 KB |
Output is partially correct |
10 |
Partially correct |
936 ms |
1108 KB |
Output is partially correct |
11 |
Partially correct |
868 ms |
1056 KB |
Output is partially correct |
12 |
Partially correct |
886 ms |
788 KB |
Output is partially correct |
13 |
Partially correct |
944 ms |
960 KB |
Output is partially correct |
14 |
Correct |
12 ms |
344 KB |
Output is correct |
15 |
Correct |
11 ms |
344 KB |
Output is correct |
16 |
Incorrect |
5 ms |
344 KB |
Incorrect |
17 |
Halted |
0 ms |
0 KB |
- |