#include "longesttrip.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
using ll = int;
std::vector<int> longest_trip(int N, int D)
{
mt19937_64 mt(random_device{}());
ll t0 = time(0);
ll n = N;
if (D==3){
vector<ll> r(n);
iota(r.begin(),r.end(),0);
return r;
}
vector<vector<ll>> a(n,vector<ll>(n,0));
for(ll i = 0;i<n;i++){
for(ll j = i+1;j<n;j++){
a[i][j] = a[j][i] = are_connected({i},{j});
}
}
vector<ll> vis(n,0);
vector<ll> ret;
vector<ll> ord(n);
iota(ord.begin(),ord.end(),0);
auto it = ord.begin();
vector<ll> cur;
function<void(ll)> dfs;
dfs = [&](ll i){
cur.push_back(i);
vis[i] = 1;
for(;it!=ord.end();it++){
ll j = *it;
if(a[i][j]&&!vis[j]){
dfs(j);
return;
}
}
};
ll cnt = 1000;
while(cnt--){
shuffle(ord.begin(),ord.end(),mt);
it = ord.begin();
dfs(ord[0]);
if(cur.size()>ret.size()) ret = cur;
cur.clear();
fill(vis.begin(),vis.end(),0);
}
return ret;
}
Compilation message
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:11:8: warning: unused variable 't0' [-Wunused-variable]
11 | ll t0 = time(0);
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
224 ms |
684 KB |
Incorrect |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
344 KB |
Output is correct |
2 |
Correct |
47 ms |
344 KB |
Output is correct |
3 |
Correct |
173 ms |
344 KB |
Output is correct |
4 |
Correct |
416 ms |
484 KB |
Output is correct |
5 |
Correct |
821 ms |
684 KB |
Output is correct |
6 |
Correct |
30 ms |
344 KB |
Output is correct |
7 |
Correct |
47 ms |
344 KB |
Output is correct |
8 |
Correct |
142 ms |
344 KB |
Output is correct |
9 |
Correct |
335 ms |
592 KB |
Output is correct |
10 |
Correct |
875 ms |
688 KB |
Output is correct |
11 |
Correct |
865 ms |
696 KB |
Output is correct |
12 |
Correct |
841 ms |
688 KB |
Output is correct |
13 |
Correct |
883 ms |
692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
344 KB |
Output is correct |
2 |
Correct |
36 ms |
344 KB |
Output is correct |
3 |
Correct |
186 ms |
344 KB |
Output is correct |
4 |
Correct |
461 ms |
592 KB |
Output is correct |
5 |
Correct |
921 ms |
692 KB |
Output is correct |
6 |
Correct |
27 ms |
344 KB |
Output is correct |
7 |
Correct |
38 ms |
344 KB |
Output is correct |
8 |
Correct |
157 ms |
344 KB |
Output is correct |
9 |
Correct |
347 ms |
344 KB |
Output is correct |
10 |
Correct |
891 ms |
688 KB |
Output is correct |
11 |
Correct |
863 ms |
688 KB |
Output is correct |
12 |
Correct |
838 ms |
684 KB |
Output is correct |
13 |
Correct |
831 ms |
684 KB |
Output is correct |
14 |
Correct |
24 ms |
344 KB |
Output is correct |
15 |
Correct |
28 ms |
344 KB |
Output is correct |
16 |
Correct |
62 ms |
344 KB |
Output is correct |
17 |
Correct |
89 ms |
344 KB |
Output is correct |
18 |
Correct |
166 ms |
344 KB |
Output is correct |
19 |
Correct |
288 ms |
460 KB |
Output is correct |
20 |
Correct |
314 ms |
460 KB |
Output is correct |
21 |
Correct |
893 ms |
948 KB |
Output is correct |
22 |
Correct |
861 ms |
688 KB |
Output is correct |
23 |
Correct |
851 ms |
704 KB |
Output is correct |
24 |
Correct |
833 ms |
700 KB |
Output is correct |
25 |
Correct |
31 ms |
344 KB |
Output is correct |
26 |
Correct |
26 ms |
344 KB |
Output is correct |
27 |
Correct |
40 ms |
344 KB |
Output is correct |
28 |
Correct |
38 ms |
344 KB |
Output is correct |
29 |
Correct |
38 ms |
344 KB |
Output is correct |
30 |
Correct |
216 ms |
344 KB |
Output is correct |
31 |
Correct |
215 ms |
344 KB |
Output is correct |
32 |
Correct |
217 ms |
344 KB |
Output is correct |
33 |
Correct |
343 ms |
456 KB |
Output is correct |
34 |
Correct |
339 ms |
344 KB |
Output is correct |
35 |
Correct |
310 ms |
340 KB |
Output is correct |
36 |
Correct |
865 ms |
684 KB |
Output is correct |
37 |
Correct |
873 ms |
848 KB |
Output is correct |
38 |
Correct |
865 ms |
684 KB |
Output is correct |
39 |
Correct |
879 ms |
600 KB |
Output is correct |
40 |
Correct |
885 ms |
688 KB |
Output is correct |
41 |
Correct |
869 ms |
688 KB |
Output is correct |
42 |
Correct |
885 ms |
848 KB |
Output is correct |
43 |
Correct |
850 ms |
600 KB |
Output is correct |
44 |
Correct |
909 ms |
688 KB |
Output is correct |
45 |
Correct |
28 ms |
344 KB |
Output is correct |
46 |
Correct |
29 ms |
344 KB |
Output is correct |
47 |
Correct |
33 ms |
344 KB |
Output is correct |
48 |
Correct |
37 ms |
344 KB |
Output is correct |
49 |
Correct |
36 ms |
344 KB |
Output is correct |
50 |
Correct |
183 ms |
344 KB |
Output is correct |
51 |
Correct |
230 ms |
344 KB |
Output is correct |
52 |
Correct |
237 ms |
344 KB |
Output is correct |
53 |
Correct |
319 ms |
344 KB |
Output is correct |
54 |
Correct |
298 ms |
476 KB |
Output is correct |
55 |
Correct |
297 ms |
344 KB |
Output is correct |
56 |
Correct |
790 ms |
684 KB |
Output is correct |
57 |
Correct |
838 ms |
688 KB |
Output is correct |
58 |
Correct |
875 ms |
684 KB |
Output is correct |
59 |
Correct |
889 ms |
680 KB |
Output is correct |
60 |
Correct |
830 ms |
680 KB |
Output is correct |
61 |
Correct |
833 ms |
688 KB |
Output is correct |
62 |
Correct |
888 ms |
684 KB |
Output is correct |
63 |
Correct |
881 ms |
684 KB |
Output is correct |
64 |
Correct |
832 ms |
692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
344 KB |
Output is correct |
2 |
Correct |
40 ms |
344 KB |
Output is correct |
3 |
Partially correct |
169 ms |
344 KB |
Output is partially correct |
4 |
Partially correct |
435 ms |
344 KB |
Output is partially correct |
5 |
Partially correct |
783 ms |
684 KB |
Output is partially correct |
6 |
Correct |
26 ms |
340 KB |
Output is correct |
7 |
Correct |
46 ms |
344 KB |
Output is correct |
8 |
Partially correct |
165 ms |
340 KB |
Output is partially correct |
9 |
Partially correct |
326 ms |
460 KB |
Output is partially correct |
10 |
Partially correct |
858 ms |
680 KB |
Output is partially correct |
11 |
Partially correct |
886 ms |
680 KB |
Output is partially correct |
12 |
Partially correct |
748 ms |
684 KB |
Output is partially correct |
13 |
Partially correct |
919 ms |
688 KB |
Output is partially correct |
14 |
Correct |
26 ms |
344 KB |
Output is correct |
15 |
Correct |
37 ms |
344 KB |
Output is correct |
16 |
Incorrect |
2 ms |
344 KB |
Incorrect |
17 |
Halted |
0 ms |
0 KB |
- |