#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];
void dfs(int x){
vis[x]=1;
out.push_back(x);
vector<int> ord;
for(int i=1;i<=n;i++){
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)
{
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:66:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | 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 |
181 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
28 ms |
344 KB |
Output is correct |
3 |
Correct |
116 ms |
344 KB |
Output is correct |
4 |
Correct |
391 ms |
456 KB |
Output is correct |
5 |
Correct |
779 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
25 ms |
344 KB |
Output is correct |
3 |
Correct |
134 ms |
596 KB |
Output is correct |
4 |
Correct |
367 ms |
452 KB |
Output is correct |
5 |
Correct |
786 ms |
484 KB |
Output is correct |
6 |
Correct |
7 ms |
344 KB |
Output is correct |
7 |
Incorrect |
4 ms |
344 KB |
Incorrect |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
23 ms |
344 KB |
Output is correct |
3 |
Correct |
113 ms |
600 KB |
Output is correct |
4 |
Correct |
353 ms |
452 KB |
Output is correct |
5 |
Correct |
710 ms |
856 KB |
Output is correct |
6 |
Correct |
9 ms |
340 KB |
Output is correct |
7 |
Correct |
25 ms |
344 KB |
Output is correct |
8 |
Correct |
121 ms |
344 KB |
Output is correct |
9 |
Correct |
256 ms |
600 KB |
Output is correct |
10 |
Correct |
675 ms |
856 KB |
Output is correct |
11 |
Correct |
703 ms |
600 KB |
Output is correct |
12 |
Correct |
690 ms |
600 KB |
Output is correct |
13 |
Correct |
710 ms |
600 KB |
Output is correct |
14 |
Correct |
8 ms |
344 KB |
Output is correct |
15 |
Correct |
15 ms |
344 KB |
Output is correct |
16 |
Correct |
39 ms |
344 KB |
Output is correct |
17 |
Correct |
83 ms |
344 KB |
Output is correct |
18 |
Correct |
127 ms |
344 KB |
Output is correct |
19 |
Correct |
259 ms |
456 KB |
Output is correct |
20 |
Correct |
266 ms |
592 KB |
Output is correct |
21 |
Correct |
715 ms |
600 KB |
Output is correct |
22 |
Correct |
756 ms |
484 KB |
Output is correct |
23 |
Correct |
780 ms |
484 KB |
Output is correct |
24 |
Correct |
741 ms |
484 KB |
Output is correct |
25 |
Correct |
8 ms |
344 KB |
Output is correct |
26 |
Correct |
8 ms |
344 KB |
Output is correct |
27 |
Correct |
21 ms |
344 KB |
Output is correct |
28 |
Correct |
21 ms |
344 KB |
Output is correct |
29 |
Correct |
22 ms |
344 KB |
Output is correct |
30 |
Correct |
175 ms |
600 KB |
Output is correct |
31 |
Correct |
149 ms |
344 KB |
Output is correct |
32 |
Correct |
153 ms |
344 KB |
Output is correct |
33 |
Correct |
304 ms |
448 KB |
Output is correct |
34 |
Correct |
277 ms |
344 KB |
Output is correct |
35 |
Correct |
274 ms |
460 KB |
Output is correct |
36 |
Correct |
729 ms |
480 KB |
Output is correct |
37 |
Correct |
743 ms |
488 KB |
Output is correct |
38 |
Correct |
744 ms |
488 KB |
Output is correct |
39 |
Correct |
707 ms |
480 KB |
Output is correct |
40 |
Correct |
722 ms |
592 KB |
Output is correct |
41 |
Correct |
725 ms |
600 KB |
Output is correct |
42 |
Correct |
739 ms |
484 KB |
Output is correct |
43 |
Correct |
666 ms |
708 KB |
Output is correct |
44 |
Correct |
698 ms |
484 KB |
Output is correct |
45 |
Correct |
9 ms |
344 KB |
Output is correct |
46 |
Correct |
8 ms |
344 KB |
Output is correct |
47 |
Correct |
20 ms |
344 KB |
Output is correct |
48 |
Correct |
22 ms |
344 KB |
Output is correct |
49 |
Correct |
23 ms |
676 KB |
Output is correct |
50 |
Correct |
148 ms |
600 KB |
Output is correct |
51 |
Correct |
146 ms |
464 KB |
Output is correct |
52 |
Correct |
157 ms |
592 KB |
Output is correct |
53 |
Correct |
249 ms |
444 KB |
Output is correct |
54 |
Correct |
237 ms |
448 KB |
Output is correct |
55 |
Correct |
257 ms |
448 KB |
Output is correct |
56 |
Correct |
732 ms |
592 KB |
Output is correct |
57 |
Correct |
707 ms |
600 KB |
Output is correct |
58 |
Correct |
700 ms |
504 KB |
Output is correct |
59 |
Correct |
674 ms |
512 KB |
Output is correct |
60 |
Correct |
701 ms |
508 KB |
Output is correct |
61 |
Correct |
684 ms |
504 KB |
Output is correct |
62 |
Correct |
695 ms |
508 KB |
Output is correct |
63 |
Correct |
695 ms |
600 KB |
Output is correct |
64 |
Correct |
730 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
24 ms |
344 KB |
Output is correct |
3 |
Partially correct |
114 ms |
344 KB |
Output is partially correct |
4 |
Partially correct |
338 ms |
452 KB |
Output is partially correct |
5 |
Partially correct |
736 ms |
600 KB |
Output is partially correct |
6 |
Correct |
8 ms |
344 KB |
Output is correct |
7 |
Incorrect |
7 ms |
344 KB |
Incorrect |
8 |
Halted |
0 ms |
0 KB |
- |