#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++){
vector<int> v;
for (int j=0;j<n;j++) vis[j]=0;
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
356 KB |
Output is correct |
2 |
Correct |
248 ms |
476 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 |
118 ms |
344 KB |
Output is correct |
4 |
Correct |
387 ms |
344 KB |
Output is correct |
5 |
Correct |
813 ms |
472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
20 ms |
344 KB |
Output is correct |
3 |
Correct |
151 ms |
344 KB |
Output is correct |
4 |
Correct |
413 ms |
344 KB |
Output is correct |
5 |
Correct |
903 ms |
476 KB |
Output is correct |
6 |
Correct |
6 ms |
356 KB |
Output is correct |
7 |
Correct |
15 ms |
344 KB |
Output is correct |
8 |
Correct |
163 ms |
344 KB |
Output is correct |
9 |
Correct |
313 ms |
344 KB |
Output is correct |
10 |
Correct |
961 ms |
476 KB |
Output is correct |
11 |
Correct |
843 ms |
476 KB |
Output is correct |
12 |
Correct |
886 ms |
476 KB |
Output is correct |
13 |
Correct |
830 ms |
472 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 |
153 ms |
344 KB |
Output is correct |
4 |
Correct |
403 ms |
344 KB |
Output is correct |
5 |
Correct |
934 ms |
468 KB |
Output is correct |
6 |
Correct |
7 ms |
344 KB |
Output is correct |
7 |
Correct |
29 ms |
344 KB |
Output is correct |
8 |
Correct |
156 ms |
344 KB |
Output is correct |
9 |
Correct |
331 ms |
344 KB |
Output is correct |
10 |
Correct |
963 ms |
472 KB |
Output is correct |
11 |
Correct |
969 ms |
592 KB |
Output is correct |
12 |
Correct |
940 ms |
472 KB |
Output is correct |
13 |
Correct |
902 ms |
476 KB |
Output is correct |
14 |
Correct |
5 ms |
344 KB |
Output is correct |
15 |
Correct |
11 ms |
344 KB |
Output is correct |
16 |
Correct |
36 ms |
344 KB |
Output is correct |
17 |
Correct |
115 ms |
344 KB |
Output is correct |
18 |
Correct |
171 ms |
344 KB |
Output is correct |
19 |
Correct |
368 ms |
344 KB |
Output is correct |
20 |
Correct |
387 ms |
420 KB |
Output is correct |
21 |
Execution timed out |
1034 ms |
476 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
21 ms |
344 KB |
Output is correct |
3 |
Partially correct |
132 ms |
344 KB |
Output is partially correct |
4 |
Partially correct |
445 ms |
344 KB |
Output is partially correct |
5 |
Partially correct |
896 ms |
472 KB |
Output is partially correct |
6 |
Correct |
9 ms |
344 KB |
Output is correct |
7 |
Correct |
23 ms |
344 KB |
Output is correct |
8 |
Partially correct |
157 ms |
344 KB |
Output is partially correct |
9 |
Partially correct |
322 ms |
344 KB |
Output is partially correct |
10 |
Partially correct |
983 ms |
596 KB |
Output is partially correct |
11 |
Partially correct |
945 ms |
592 KB |
Output is partially correct |
12 |
Partially correct |
974 ms |
472 KB |
Output is partially correct |
13 |
Partially correct |
986 ms |
592 KB |
Output is partially correct |
14 |
Correct |
6 ms |
344 KB |
Output is correct |
15 |
Correct |
11 ms |
344 KB |
Output is correct |
16 |
Correct |
33 ms |
344 KB |
Output is correct |
17 |
Partially correct |
94 ms |
344 KB |
Output is partially correct |
18 |
Partially correct |
163 ms |
344 KB |
Output is partially correct |
19 |
Partially correct |
353 ms |
344 KB |
Output is partially correct |
20 |
Partially correct |
312 ms |
420 KB |
Output is partially correct |
21 |
Correct |
10 ms |
344 KB |
Output is correct |
22 |
Correct |
9 ms |
344 KB |
Output is correct |
23 |
Correct |
22 ms |
344 KB |
Output is correct |
24 |
Correct |
21 ms |
344 KB |
Output is correct |
25 |
Correct |
24 ms |
344 KB |
Output is correct |
26 |
Partially correct |
195 ms |
344 KB |
Output is partially correct |
27 |
Partially correct |
192 ms |
344 KB |
Output is partially correct |
28 |
Partially correct |
207 ms |
344 KB |
Output is partially correct |
29 |
Partially correct |
306 ms |
344 KB |
Output is partially correct |
30 |
Partially correct |
326 ms |
344 KB |
Output is partially correct |
31 |
Partially correct |
299 ms |
344 KB |
Output is partially correct |
32 |
Correct |
6 ms |
344 KB |
Output is correct |
33 |
Correct |
10 ms |
344 KB |
Output is correct |
34 |
Correct |
34 ms |
344 KB |
Output is correct |
35 |
Correct |
20 ms |
344 KB |
Output is correct |
36 |
Correct |
17 ms |
344 KB |
Output is correct |
37 |
Partially correct |
239 ms |
344 KB |
Output is partially correct |
38 |
Partially correct |
213 ms |
344 KB |
Output is partially correct |
39 |
Partially correct |
183 ms |
344 KB |
Output is partially correct |
40 |
Partially correct |
328 ms |
592 KB |
Output is partially correct |
41 |
Partially correct |
369 ms |
420 KB |
Output is partially correct |
42 |
Partially correct |
338 ms |
420 KB |
Output is partially correct |
43 |
Execution timed out |
1012 ms |
468 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |