#include "longesttrip.h"
#include <bits/stdc++.h>
#define pb push_back
#define elif else if
using namespace std;
std::vector<int> longest_trip(int n, int D)
{
vector<int> ans;
vector<bool> vis(n);
bool adj[n][n];
for (int i=0;i<n;i++){
for (int j=i+1;j<n;j++){
vector<int> x,y;
x.pb(i);y.pb(j);
adj[i][j]=adj[j][i]=are_connected(x,y);
}
}
for (int i=0;i<n;i++){
if (vis[i]) continue;
vector<int> v;
v.pb(i);vis[i]=1;
while (true){
int L=-1,R=-1;
for (int j=0;j<n;j++){
if (vis[j]) continue;
if (adj[v.back()][j]) R=j;
if (adj[v[0]][j]) L=j;
}
if (R>-1) v.pb(R),vis[R]=1;
elif(L>-1){
reverse(v.begin(),v.end());
v.pb(L);
vis[L]=1;
}
else break;
}
if (v.size()>ans.size()) ans=v;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
201 ms |
476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
22 ms |
344 KB |
Output is correct |
3 |
Correct |
148 ms |
344 KB |
Output is correct |
4 |
Correct |
396 ms |
344 KB |
Output is correct |
5 |
Correct |
786 ms |
472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
21 ms |
344 KB |
Output is correct |
3 |
Correct |
129 ms |
344 KB |
Output is correct |
4 |
Correct |
354 ms |
508 KB |
Output is correct |
5 |
Correct |
765 ms |
476 KB |
Output is correct |
6 |
Correct |
6 ms |
344 KB |
Output is correct |
7 |
Correct |
19 ms |
344 KB |
Output is correct |
8 |
Correct |
148 ms |
344 KB |
Output is correct |
9 |
Correct |
254 ms |
344 KB |
Output is correct |
10 |
Correct |
762 ms |
476 KB |
Output is correct |
11 |
Correct |
757 ms |
476 KB |
Output is correct |
12 |
Correct |
831 ms |
476 KB |
Output is correct |
13 |
Correct |
809 ms |
480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
344 KB |
Output is correct |
2 |
Correct |
20 ms |
344 KB |
Output is correct |
3 |
Correct |
143 ms |
344 KB |
Output is correct |
4 |
Correct |
369 ms |
344 KB |
Output is correct |
5 |
Correct |
797 ms |
468 KB |
Output is correct |
6 |
Correct |
5 ms |
344 KB |
Output is correct |
7 |
Correct |
24 ms |
344 KB |
Output is correct |
8 |
Correct |
129 ms |
344 KB |
Output is correct |
9 |
Correct |
299 ms |
344 KB |
Output is correct |
10 |
Correct |
825 ms |
476 KB |
Output is correct |
11 |
Correct |
835 ms |
476 KB |
Output is correct |
12 |
Correct |
822 ms |
472 KB |
Output is correct |
13 |
Correct |
650 ms |
476 KB |
Output is correct |
14 |
Correct |
9 ms |
344 KB |
Output is correct |
15 |
Correct |
13 ms |
344 KB |
Output is correct |
16 |
Correct |
32 ms |
344 KB |
Output is correct |
17 |
Correct |
73 ms |
344 KB |
Output is correct |
18 |
Correct |
131 ms |
344 KB |
Output is correct |
19 |
Correct |
299 ms |
344 KB |
Output is correct |
20 |
Correct |
292 ms |
344 KB |
Output is correct |
21 |
Correct |
870 ms |
472 KB |
Output is correct |
22 |
Correct |
855 ms |
592 KB |
Output is correct |
23 |
Correct |
791 ms |
472 KB |
Output is correct |
24 |
Correct |
784 ms |
476 KB |
Output is correct |
25 |
Correct |
9 ms |
344 KB |
Output is correct |
26 |
Correct |
12 ms |
344 KB |
Output is correct |
27 |
Correct |
24 ms |
344 KB |
Output is correct |
28 |
Correct |
26 ms |
344 KB |
Output is correct |
29 |
Correct |
17 ms |
340 KB |
Output is correct |
30 |
Correct |
199 ms |
344 KB |
Output is correct |
31 |
Correct |
187 ms |
344 KB |
Output is correct |
32 |
Correct |
187 ms |
344 KB |
Output is correct |
33 |
Correct |
284 ms |
344 KB |
Output is correct |
34 |
Correct |
313 ms |
344 KB |
Output is correct |
35 |
Correct |
282 ms |
344 KB |
Output is correct |
36 |
Correct |
830 ms |
468 KB |
Output is correct |
37 |
Correct |
860 ms |
472 KB |
Output is correct |
38 |
Correct |
833 ms |
472 KB |
Output is correct |
39 |
Correct |
802 ms |
472 KB |
Output is correct |
40 |
Correct |
783 ms |
472 KB |
Output is correct |
41 |
Correct |
797 ms |
344 KB |
Output is correct |
42 |
Correct |
754 ms |
344 KB |
Output is correct |
43 |
Correct |
748 ms |
472 KB |
Output is correct |
44 |
Correct |
850 ms |
476 KB |
Output is correct |
45 |
Correct |
8 ms |
344 KB |
Output is correct |
46 |
Correct |
8 ms |
344 KB |
Output is correct |
47 |
Correct |
21 ms |
344 KB |
Output is correct |
48 |
Correct |
21 ms |
344 KB |
Output is correct |
49 |
Correct |
26 ms |
344 KB |
Output is correct |
50 |
Correct |
186 ms |
344 KB |
Output is correct |
51 |
Correct |
190 ms |
344 KB |
Output is correct |
52 |
Correct |
187 ms |
344 KB |
Output is correct |
53 |
Correct |
284 ms |
344 KB |
Output is correct |
54 |
Correct |
312 ms |
416 KB |
Output is correct |
55 |
Correct |
289 ms |
416 KB |
Output is correct |
56 |
Correct |
795 ms |
472 KB |
Output is correct |
57 |
Correct |
748 ms |
476 KB |
Output is correct |
58 |
Correct |
699 ms |
476 KB |
Output is correct |
59 |
Correct |
749 ms |
476 KB |
Output is correct |
60 |
Correct |
861 ms |
472 KB |
Output is correct |
61 |
Correct |
835 ms |
476 KB |
Output is correct |
62 |
Correct |
828 ms |
472 KB |
Output is correct |
63 |
Correct |
867 ms |
476 KB |
Output is correct |
64 |
Correct |
849 ms |
472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
344 KB |
Output is correct |
2 |
Correct |
16 ms |
344 KB |
Output is correct |
3 |
Partially correct |
158 ms |
344 KB |
Output is partially correct |
4 |
Partially correct |
408 ms |
344 KB |
Output is partially correct |
5 |
Partially correct |
886 ms |
476 KB |
Output is partially correct |
6 |
Correct |
7 ms |
344 KB |
Output is correct |
7 |
Correct |
27 ms |
344 KB |
Output is correct |
8 |
Partially correct |
164 ms |
344 KB |
Output is partially correct |
9 |
Partially correct |
323 ms |
344 KB |
Output is partially correct |
10 |
Partially correct |
871 ms |
488 KB |
Output is partially correct |
11 |
Partially correct |
822 ms |
472 KB |
Output is partially correct |
12 |
Partially correct |
692 ms |
476 KB |
Output is partially correct |
13 |
Partially correct |
751 ms |
472 KB |
Output is partially correct |
14 |
Correct |
5 ms |
344 KB |
Output is correct |
15 |
Correct |
9 ms |
344 KB |
Output is correct |
16 |
Incorrect |
4 ms |
344 KB |
Incorrect |
17 |
Halted |
0 ms |
0 KB |
- |