#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=0;i<=n-1;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:67:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for(int i=1;i<vec.size();i++){
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
175 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
344 KB |
Output is correct |
2 |
Correct |
20 ms |
344 KB |
Output is correct |
3 |
Correct |
114 ms |
344 KB |
Output is correct |
4 |
Correct |
353 ms |
452 KB |
Output is correct |
5 |
Correct |
770 ms |
484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
340 KB |
Output is correct |
2 |
Correct |
28 ms |
344 KB |
Output is correct |
3 |
Correct |
122 ms |
344 KB |
Output is correct |
4 |
Correct |
370 ms |
720 KB |
Output is correct |
5 |
Correct |
880 ms |
488 KB |
Output is correct |
6 |
Correct |
7 ms |
344 KB |
Output is correct |
7 |
Correct |
22 ms |
344 KB |
Output is correct |
8 |
Correct |
121 ms |
344 KB |
Output is correct |
9 |
Correct |
262 ms |
464 KB |
Output is correct |
10 |
Correct |
763 ms |
480 KB |
Output is correct |
11 |
Correct |
736 ms |
480 KB |
Output is correct |
12 |
Correct |
770 ms |
600 KB |
Output is correct |
13 |
Correct |
779 ms |
484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
26 ms |
344 KB |
Output is correct |
3 |
Correct |
109 ms |
344 KB |
Output is correct |
4 |
Correct |
323 ms |
456 KB |
Output is correct |
5 |
Correct |
732 ms |
600 KB |
Output is correct |
6 |
Correct |
8 ms |
344 KB |
Output is correct |
7 |
Correct |
19 ms |
344 KB |
Output is correct |
8 |
Correct |
107 ms |
344 KB |
Output is correct |
9 |
Correct |
257 ms |
592 KB |
Output is correct |
10 |
Correct |
777 ms |
480 KB |
Output is correct |
11 |
Correct |
729 ms |
484 KB |
Output is correct |
12 |
Correct |
756 ms |
500 KB |
Output is correct |
13 |
Correct |
702 ms |
480 KB |
Output is correct |
14 |
Correct |
6 ms |
344 KB |
Output is correct |
15 |
Correct |
13 ms |
344 KB |
Output is correct |
16 |
Correct |
46 ms |
344 KB |
Output is correct |
17 |
Correct |
95 ms |
600 KB |
Output is correct |
18 |
Correct |
133 ms |
344 KB |
Output is correct |
19 |
Correct |
265 ms |
600 KB |
Output is correct |
20 |
Correct |
293 ms |
596 KB |
Output is correct |
21 |
Correct |
759 ms |
600 KB |
Output is correct |
22 |
Correct |
773 ms |
600 KB |
Output is correct |
23 |
Correct |
757 ms |
488 KB |
Output is correct |
24 |
Correct |
739 ms |
592 KB |
Output is correct |
25 |
Correct |
9 ms |
344 KB |
Output is correct |
26 |
Correct |
8 ms |
344 KB |
Output is correct |
27 |
Correct |
19 ms |
344 KB |
Output is correct |
28 |
Correct |
20 ms |
344 KB |
Output is correct |
29 |
Correct |
19 ms |
344 KB |
Output is correct |
30 |
Correct |
163 ms |
444 KB |
Output is correct |
31 |
Correct |
174 ms |
452 KB |
Output is correct |
32 |
Correct |
172 ms |
448 KB |
Output is correct |
33 |
Correct |
265 ms |
452 KB |
Output is correct |
34 |
Correct |
279 ms |
344 KB |
Output is correct |
35 |
Correct |
272 ms |
592 KB |
Output is correct |
36 |
Correct |
710 ms |
484 KB |
Output is correct |
37 |
Correct |
729 ms |
488 KB |
Output is correct |
38 |
Correct |
819 ms |
480 KB |
Output is correct |
39 |
Correct |
788 ms |
480 KB |
Output is correct |
40 |
Correct |
782 ms |
504 KB |
Output is correct |
41 |
Correct |
760 ms |
484 KB |
Output is correct |
42 |
Correct |
738 ms |
600 KB |
Output is correct |
43 |
Correct |
703 ms |
592 KB |
Output is correct |
44 |
Correct |
700 ms |
480 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 |
25 ms |
344 KB |
Output is correct |
49 |
Correct |
22 ms |
344 KB |
Output is correct |
50 |
Correct |
146 ms |
448 KB |
Output is correct |
51 |
Correct |
150 ms |
448 KB |
Output is correct |
52 |
Correct |
155 ms |
700 KB |
Output is correct |
53 |
Correct |
290 ms |
444 KB |
Output is correct |
54 |
Correct |
246 ms |
592 KB |
Output is correct |
55 |
Correct |
271 ms |
456 KB |
Output is correct |
56 |
Correct |
734 ms |
512 KB |
Output is correct |
57 |
Correct |
750 ms |
512 KB |
Output is correct |
58 |
Correct |
737 ms |
508 KB |
Output is correct |
59 |
Correct |
682 ms |
524 KB |
Output is correct |
60 |
Correct |
717 ms |
600 KB |
Output is correct |
61 |
Correct |
748 ms |
596 KB |
Output is correct |
62 |
Correct |
751 ms |
760 KB |
Output is correct |
63 |
Correct |
828 ms |
592 KB |
Output is correct |
64 |
Correct |
839 ms |
616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
344 KB |
Output is correct |
2 |
Correct |
20 ms |
344 KB |
Output is correct |
3 |
Partially correct |
109 ms |
344 KB |
Output is partially correct |
4 |
Partially correct |
367 ms |
452 KB |
Output is partially correct |
5 |
Partially correct |
755 ms |
488 KB |
Output is partially correct |
6 |
Correct |
6 ms |
344 KB |
Output is correct |
7 |
Correct |
28 ms |
344 KB |
Output is correct |
8 |
Partially correct |
121 ms |
344 KB |
Output is partially correct |
9 |
Partially correct |
258 ms |
464 KB |
Output is partially correct |
10 |
Partially correct |
732 ms |
596 KB |
Output is partially correct |
11 |
Partially correct |
706 ms |
484 KB |
Output is partially correct |
12 |
Partially correct |
765 ms |
484 KB |
Output is partially correct |
13 |
Partially correct |
719 ms |
480 KB |
Output is partially correct |
14 |
Correct |
8 ms |
596 KB |
Output is correct |
15 |
Correct |
12 ms |
344 KB |
Output is correct |
16 |
Incorrect |
5 ms |
344 KB |
Incorrect |
17 |
Halted |
0 ms |
0 KB |
- |