#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng(0);
std::vector<int> longest_trip(int N, int D)
{
vector<int>x,y;
x.push_back(0);
for(int i=1;i<N;i++){
if(are_connected({0}, {i})){
x.push_back(i);
} else{
y.push_back(i);
}
}
if(y.size()>0 && !are_connected(x,y)){
if(x.size()>y.size()){
return x;
} else{
return y;
}
}
// if(y.empty()){
vector<int>ans;
vector<int>p;
ans.push_back(x.back());
for(int i=1;i<N;i++){
p.push_back(i);
}
p.erase(find(p.begin(),p.end(), x.back()));
while(!p.empty()){
shuffle(p.begin(),p.end(),rng);
bool found=false;
for(int i: p){
if(are_connected({ans.back()}, {i})){
ans.push_back(i);
p.erase(find(p.begin(),p.end(), i));
found=true;
break;
}
}
if(!found){
break;
}
}
reverse(ans.begin(),ans.end());
ans.push_back(0);
for(int i=0;i<p.size();i++){
if(find(x.begin(),x.end(), p[i])!=x.end()){
swap(p[i], p[0]);
break;
}
}
for(int i: p){
ans.push_back(i);
}
return ans;
// }
}
Compilation message
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:49:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for(int i=0;i<p.size();i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
8 ms |
344 KB |
Output is correct |
3 |
Correct |
10 ms |
344 KB |
Output is correct |
4 |
Correct |
10 ms |
344 KB |
Output is correct |
5 |
Correct |
12 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
8 ms |
596 KB |
Output is correct |
3 |
Correct |
10 ms |
344 KB |
Output is correct |
4 |
Correct |
10 ms |
344 KB |
Output is correct |
5 |
Correct |
11 ms |
344 KB |
Output is correct |
6 |
Correct |
7 ms |
344 KB |
Output is correct |
7 |
Correct |
14 ms |
344 KB |
Output is correct |
8 |
Correct |
9 ms |
344 KB |
Output is correct |
9 |
Correct |
11 ms |
856 KB |
Output is correct |
10 |
Correct |
12 ms |
344 KB |
Output is correct |
11 |
Correct |
11 ms |
344 KB |
Output is correct |
12 |
Correct |
11 ms |
344 KB |
Output is correct |
13 |
Correct |
10 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
8 ms |
344 KB |
Output is correct |
3 |
Correct |
10 ms |
500 KB |
Output is correct |
4 |
Correct |
9 ms |
344 KB |
Output is correct |
5 |
Correct |
12 ms |
596 KB |
Output is correct |
6 |
Correct |
11 ms |
344 KB |
Output is correct |
7 |
Correct |
9 ms |
344 KB |
Output is correct |
8 |
Correct |
9 ms |
344 KB |
Output is correct |
9 |
Correct |
9 ms |
344 KB |
Output is correct |
10 |
Correct |
10 ms |
344 KB |
Output is correct |
11 |
Correct |
11 ms |
344 KB |
Output is correct |
12 |
Correct |
11 ms |
344 KB |
Output is correct |
13 |
Correct |
13 ms |
600 KB |
Output is correct |
14 |
Correct |
7 ms |
344 KB |
Output is correct |
15 |
Correct |
6 ms |
344 KB |
Output is correct |
16 |
Incorrect |
5 ms |
344 KB |
Incorrect |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
596 KB |
Output is correct |
2 |
Correct |
10 ms |
344 KB |
Output is correct |
3 |
Correct |
9 ms |
344 KB |
Output is correct |
4 |
Correct |
10 ms |
344 KB |
Output is correct |
5 |
Partially correct |
12 ms |
344 KB |
Output is partially correct |
6 |
Correct |
8 ms |
344 KB |
Output is correct |
7 |
Correct |
9 ms |
344 KB |
Output is correct |
8 |
Correct |
9 ms |
600 KB |
Output is correct |
9 |
Correct |
9 ms |
344 KB |
Output is correct |
10 |
Partially correct |
11 ms |
344 KB |
Output is partially correct |
11 |
Partially correct |
10 ms |
344 KB |
Output is partially correct |
12 |
Partially correct |
11 ms |
344 KB |
Output is partially correct |
13 |
Partially correct |
12 ms |
700 KB |
Output is partially correct |
14 |
Correct |
6 ms |
344 KB |
Output is correct |
15 |
Correct |
6 ms |
600 KB |
Output is correct |
16 |
Incorrect |
5 ms |
344 KB |
Incorrect |
17 |
Halted |
0 ms |
0 KB |
- |