#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(int i=0;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)
{
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++){
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
177 ms |
484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
344 KB |
Output is correct |
2 |
Correct |
22 ms |
344 KB |
Output is correct |
3 |
Correct |
117 ms |
344 KB |
Output is correct |
4 |
Correct |
356 ms |
592 KB |
Output is correct |
5 |
Correct |
696 ms |
488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
19 ms |
344 KB |
Output is correct |
3 |
Correct |
119 ms |
344 KB |
Output is correct |
4 |
Correct |
368 ms |
592 KB |
Output is correct |
5 |
Correct |
780 ms |
488 KB |
Output is correct |
6 |
Correct |
8 ms |
344 KB |
Output is correct |
7 |
Correct |
22 ms |
448 KB |
Output is correct |
8 |
Correct |
125 ms |
592 KB |
Output is correct |
9 |
Correct |
274 ms |
592 KB |
Output is correct |
10 |
Correct |
794 ms |
480 KB |
Output is correct |
11 |
Correct |
794 ms |
480 KB |
Output is correct |
12 |
Correct |
796 ms |
480 KB |
Output is correct |
13 |
Correct |
798 ms |
484 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 |
120 ms |
600 KB |
Output is correct |
4 |
Correct |
338 ms |
452 KB |
Output is correct |
5 |
Correct |
774 ms |
856 KB |
Output is correct |
6 |
Correct |
6 ms |
344 KB |
Output is correct |
7 |
Correct |
20 ms |
344 KB |
Output is correct |
8 |
Correct |
128 ms |
344 KB |
Output is correct |
9 |
Correct |
270 ms |
592 KB |
Output is correct |
10 |
Correct |
755 ms |
480 KB |
Output is correct |
11 |
Correct |
685 ms |
600 KB |
Output is correct |
12 |
Correct |
753 ms |
480 KB |
Output is correct |
13 |
Correct |
757 ms |
596 KB |
Output is correct |
14 |
Correct |
6 ms |
352 KB |
Output is correct |
15 |
Correct |
14 ms |
596 KB |
Output is correct |
16 |
Correct |
42 ms |
344 KB |
Output is correct |
17 |
Correct |
74 ms |
344 KB |
Output is correct |
18 |
Correct |
124 ms |
344 KB |
Output is correct |
19 |
Correct |
248 ms |
448 KB |
Output is correct |
20 |
Correct |
258 ms |
592 KB |
Output is correct |
21 |
Correct |
727 ms |
484 KB |
Output is correct |
22 |
Correct |
749 ms |
480 KB |
Output is correct |
23 |
Correct |
717 ms |
492 KB |
Output is correct |
24 |
Correct |
746 ms |
500 KB |
Output is correct |
25 |
Correct |
9 ms |
344 KB |
Output is correct |
26 |
Correct |
9 ms |
344 KB |
Output is correct |
27 |
Correct |
23 ms |
344 KB |
Output is correct |
28 |
Correct |
23 ms |
344 KB |
Output is correct |
29 |
Correct |
18 ms |
344 KB |
Output is correct |
30 |
Correct |
151 ms |
444 KB |
Output is correct |
31 |
Correct |
152 ms |
452 KB |
Output is correct |
32 |
Correct |
151 ms |
448 KB |
Output is correct |
33 |
Correct |
248 ms |
592 KB |
Output is correct |
34 |
Correct |
243 ms |
464 KB |
Output is correct |
35 |
Correct |
261 ms |
460 KB |
Output is correct |
36 |
Correct |
691 ms |
488 KB |
Output is correct |
37 |
Correct |
729 ms |
484 KB |
Output is correct |
38 |
Correct |
753 ms |
852 KB |
Output is correct |
39 |
Correct |
765 ms |
600 KB |
Output is correct |
40 |
Correct |
735 ms |
600 KB |
Output is correct |
41 |
Correct |
722 ms |
488 KB |
Output is correct |
42 |
Correct |
730 ms |
484 KB |
Output is correct |
43 |
Correct |
660 ms |
484 KB |
Output is correct |
44 |
Correct |
707 ms |
484 KB |
Output is correct |
45 |
Correct |
10 ms |
344 KB |
Output is correct |
46 |
Correct |
8 ms |
344 KB |
Output is correct |
47 |
Correct |
24 ms |
344 KB |
Output is correct |
48 |
Correct |
19 ms |
344 KB |
Output is correct |
49 |
Correct |
24 ms |
344 KB |
Output is correct |
50 |
Correct |
176 ms |
448 KB |
Output is correct |
51 |
Correct |
176 ms |
440 KB |
Output is correct |
52 |
Correct |
159 ms |
448 KB |
Output is correct |
53 |
Correct |
238 ms |
448 KB |
Output is correct |
54 |
Correct |
265 ms |
456 KB |
Output is correct |
55 |
Correct |
249 ms |
704 KB |
Output is correct |
56 |
Correct |
805 ms |
488 KB |
Output is correct |
57 |
Correct |
767 ms |
1112 KB |
Output is correct |
58 |
Correct |
714 ms |
504 KB |
Output is correct |
59 |
Correct |
744 ms |
496 KB |
Output is correct |
60 |
Correct |
701 ms |
496 KB |
Output is correct |
61 |
Correct |
759 ms |
748 KB |
Output is correct |
62 |
Correct |
778 ms |
600 KB |
Output is correct |
63 |
Correct |
714 ms |
500 KB |
Output is correct |
64 |
Correct |
753 ms |
496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
23 ms |
344 KB |
Output is correct |
3 |
Partially correct |
117 ms |
344 KB |
Output is partially correct |
4 |
Partially correct |
351 ms |
452 KB |
Output is partially correct |
5 |
Partially correct |
709 ms |
856 KB |
Output is partially correct |
6 |
Correct |
6 ms |
344 KB |
Output is correct |
7 |
Correct |
24 ms |
344 KB |
Output is correct |
8 |
Partially correct |
130 ms |
344 KB |
Output is partially correct |
9 |
Partially correct |
272 ms |
444 KB |
Output is partially correct |
10 |
Partially correct |
747 ms |
484 KB |
Output is partially correct |
11 |
Partially correct |
730 ms |
484 KB |
Output is partially correct |
12 |
Partially correct |
696 ms |
484 KB |
Output is partially correct |
13 |
Partially correct |
704 ms |
856 KB |
Output is partially correct |
14 |
Correct |
6 ms |
344 KB |
Output is correct |
15 |
Correct |
11 ms |
344 KB |
Output is correct |
16 |
Incorrect |
6 ms |
344 KB |
Incorrect |
17 |
Halted |
0 ms |
0 KB |
- |