#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
const int MAXN = 260;
const int inf=1000000500ll;
const long long oo =1000000000000000500ll;
const int MOD = (int)1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int> pi;
vector<int>out;
int n,d;
bool mat[MAXN][MAXN];
bool vis[MAXN];
vector<int> ord;
void dfs(int x){
vis[x]=1;
out.push_back(x);
for(auto i:ord){
if(mat[x][i] && !vis[i]){
dfs(i);
return;
}
}
}
vector<int>solve(int st){
memset(vis,0,sizeof vis);
out.clear();
dfs(st);
return out;
}
std::vector<int> longest_trip(int N, int D)
{
ord.clear();
for(int i=0;i<N;i++){
ord.push_back(i);
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
mat[i][j]=0;
}
}
n=N;
d=D;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
vector<int>A;A.push_back(i);
vector<int>B;B.push_back(j);
mat[i][j]=mat[j][i]=are_connected(A,B);
}
}
if(n<=9){
vector<int> vec;
vector<int> ans;
for(int i=0;i<n;i++)vec.push_back(i);
do {
int cur=vec[0];
vector<int>hh;
hh.push_back(cur);
for(int i=1;i<vec.size();i++){
if(mat[cur][vec[i]]){
hh.push_back(vec[i]);
cur=vec[i];
}
}
if(hh.size()>ans.size())ans=hh;
} while(next_permutation(vec.begin(),vec.end()));
return ans;
}
vector<int> ans;
for(int i=0;i<n;i++){//starting point
vector<int>res=solve(i);
if(res.size()>ans.size())ans=res;
}
return ans;
}
Compilation message
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:72:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for(int i=1;i<vec.size();i++){
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
175 ms |
488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
26 ms |
344 KB |
Output is correct |
3 |
Correct |
110 ms |
344 KB |
Output is correct |
4 |
Correct |
367 ms |
592 KB |
Output is correct |
5 |
Correct |
771 ms |
488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
344 KB |
Output is correct |
2 |
Correct |
25 ms |
344 KB |
Output is correct |
3 |
Correct |
117 ms |
600 KB |
Output is correct |
4 |
Correct |
352 ms |
456 KB |
Output is correct |
5 |
Correct |
727 ms |
488 KB |
Output is correct |
6 |
Correct |
6 ms |
344 KB |
Output is correct |
7 |
Correct |
21 ms |
340 KB |
Output is correct |
8 |
Correct |
121 ms |
344 KB |
Output is correct |
9 |
Correct |
258 ms |
600 KB |
Output is correct |
10 |
Correct |
773 ms |
600 KB |
Output is correct |
11 |
Correct |
733 ms |
484 KB |
Output is correct |
12 |
Correct |
731 ms |
856 KB |
Output is correct |
13 |
Correct |
744 ms |
484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
24 ms |
340 KB |
Output is correct |
3 |
Correct |
117 ms |
344 KB |
Output is correct |
4 |
Correct |
336 ms |
460 KB |
Output is correct |
5 |
Correct |
738 ms |
600 KB |
Output is correct |
6 |
Correct |
7 ms |
344 KB |
Output is correct |
7 |
Correct |
21 ms |
344 KB |
Output is correct |
8 |
Correct |
133 ms |
344 KB |
Output is correct |
9 |
Correct |
272 ms |
600 KB |
Output is correct |
10 |
Correct |
730 ms |
492 KB |
Output is correct |
11 |
Correct |
723 ms |
600 KB |
Output is correct |
12 |
Correct |
705 ms |
856 KB |
Output is correct |
13 |
Correct |
778 ms |
560 KB |
Output is correct |
14 |
Correct |
6 ms |
344 KB |
Output is correct |
15 |
Correct |
11 ms |
344 KB |
Output is correct |
16 |
Correct |
38 ms |
344 KB |
Output is correct |
17 |
Correct |
75 ms |
344 KB |
Output is correct |
18 |
Correct |
108 ms |
344 KB |
Output is correct |
19 |
Correct |
256 ms |
444 KB |
Output is correct |
20 |
Correct |
231 ms |
448 KB |
Output is correct |
21 |
Correct |
738 ms |
592 KB |
Output is correct |
22 |
Correct |
763 ms |
488 KB |
Output is correct |
23 |
Correct |
751 ms |
596 KB |
Output is correct |
24 |
Correct |
778 ms |
600 KB |
Output is correct |
25 |
Correct |
8 ms |
344 KB |
Output is correct |
26 |
Correct |
9 ms |
344 KB |
Output is correct |
27 |
Correct |
19 ms |
344 KB |
Output is correct |
28 |
Correct |
19 ms |
344 KB |
Output is correct |
29 |
Correct |
21 ms |
344 KB |
Output is correct |
30 |
Correct |
159 ms |
448 KB |
Output is correct |
31 |
Correct |
193 ms |
448 KB |
Output is correct |
32 |
Correct |
156 ms |
444 KB |
Output is correct |
33 |
Correct |
270 ms |
464 KB |
Output is correct |
34 |
Correct |
272 ms |
444 KB |
Output is correct |
35 |
Correct |
265 ms |
344 KB |
Output is correct |
36 |
Correct |
757 ms |
488 KB |
Output is correct |
37 |
Correct |
741 ms |
488 KB |
Output is correct |
38 |
Correct |
755 ms |
492 KB |
Output is correct |
39 |
Correct |
727 ms |
344 KB |
Output is correct |
40 |
Correct |
706 ms |
344 KB |
Output is correct |
41 |
Correct |
726 ms |
344 KB |
Output is correct |
42 |
Correct |
773 ms |
344 KB |
Output is correct |
43 |
Correct |
720 ms |
344 KB |
Output is correct |
44 |
Correct |
738 ms |
344 KB |
Output is correct |
45 |
Correct |
11 ms |
344 KB |
Output is correct |
46 |
Correct |
9 ms |
344 KB |
Output is correct |
47 |
Correct |
25 ms |
344 KB |
Output is correct |
48 |
Correct |
27 ms |
600 KB |
Output is correct |
49 |
Correct |
20 ms |
344 KB |
Output is correct |
50 |
Correct |
168 ms |
448 KB |
Output is correct |
51 |
Correct |
157 ms |
692 KB |
Output is correct |
52 |
Correct |
157 ms |
456 KB |
Output is correct |
53 |
Correct |
246 ms |
444 KB |
Output is correct |
54 |
Correct |
260 ms |
452 KB |
Output is correct |
55 |
Correct |
256 ms |
452 KB |
Output is correct |
56 |
Correct |
791 ms |
488 KB |
Output is correct |
57 |
Correct |
794 ms |
600 KB |
Output is correct |
58 |
Correct |
767 ms |
492 KB |
Output is correct |
59 |
Correct |
729 ms |
856 KB |
Output is correct |
60 |
Correct |
725 ms |
496 KB |
Output is correct |
61 |
Correct |
738 ms |
496 KB |
Output is correct |
62 |
Correct |
710 ms |
500 KB |
Output is correct |
63 |
Correct |
734 ms |
756 KB |
Output is correct |
64 |
Correct |
798 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
344 KB |
Output is correct |
2 |
Correct |
21 ms |
344 KB |
Output is correct |
3 |
Partially correct |
117 ms |
344 KB |
Output is partially correct |
4 |
Partially correct |
319 ms |
456 KB |
Output is partially correct |
5 |
Partially correct |
702 ms |
496 KB |
Output is partially correct |
6 |
Correct |
6 ms |
344 KB |
Output is correct |
7 |
Correct |
24 ms |
352 KB |
Output is correct |
8 |
Partially correct |
121 ms |
344 KB |
Output is partially correct |
9 |
Partially correct |
269 ms |
448 KB |
Output is partially correct |
10 |
Partially correct |
757 ms |
492 KB |
Output is partially correct |
11 |
Partially correct |
766 ms |
488 KB |
Output is partially correct |
12 |
Partially correct |
731 ms |
344 KB |
Output is partially correct |
13 |
Partially correct |
707 ms |
488 KB |
Output is partially correct |
14 |
Correct |
7 ms |
344 KB |
Output is correct |
15 |
Correct |
13 ms |
344 KB |
Output is correct |
16 |
Incorrect |
6 ms |
344 KB |
Incorrect |
17 |
Halted |
0 ms |
0 KB |
- |