#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({1});
for(int i=2;i<N;i++){
p.push_back(i);
}
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;
}
}
ans.push_back(0);
for(int i: p){
ans.push_back(i);
}
return ans;
}
vector<int>ans=y;
vector<int>p;
for(int i=1;i<N;i++){
if(find(y.begin(),y.end(),i)==y.end()){
p.push_back(i);
}
}
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;
}
}
ans.push_back(0);
for(int i: p){
ans.push_back(i);
}
return ans;
}
# |
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 |
9 ms |
344 KB |
Output is correct |
4 |
Correct |
9 ms |
344 KB |
Output is correct |
5 |
Correct |
13 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
344 KB |
Output is correct |
2 |
Correct |
8 ms |
344 KB |
Output is correct |
3 |
Correct |
9 ms |
344 KB |
Output is correct |
4 |
Correct |
9 ms |
344 KB |
Output is correct |
5 |
Correct |
10 ms |
344 KB |
Output is correct |
6 |
Correct |
8 ms |
344 KB |
Output is correct |
7 |
Correct |
8 ms |
344 KB |
Output is correct |
8 |
Correct |
11 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 |
600 KB |
Output is correct |
13 |
Correct |
11 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
340 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 |
13 ms |
600 KB |
Output is correct |
6 |
Correct |
8 ms |
344 KB |
Output is correct |
7 |
Correct |
11 ms |
344 KB |
Output is correct |
8 |
Correct |
8 ms |
344 KB |
Output is correct |
9 |
Correct |
9 ms |
600 KB |
Output is correct |
10 |
Correct |
10 ms |
344 KB |
Output is correct |
11 |
Correct |
12 ms |
600 KB |
Output is correct |
12 |
Correct |
10 ms |
344 KB |
Output is correct |
13 |
Correct |
10 ms |
600 KB |
Output is correct |
14 |
Correct |
6 ms |
596 KB |
Output is correct |
15 |
Correct |
6 ms |
344 KB |
Output is correct |
16 |
Correct |
10 ms |
344 KB |
Output is correct |
17 |
Correct |
9 ms |
600 KB |
Output is correct |
18 |
Correct |
10 ms |
600 KB |
Output is correct |
19 |
Correct |
9 ms |
596 KB |
Output is correct |
20 |
Correct |
9 ms |
444 KB |
Output is correct |
21 |
Correct |
10 ms |
604 KB |
Output is correct |
22 |
Correct |
11 ms |
700 KB |
Output is correct |
23 |
Correct |
10 ms |
604 KB |
Output is correct |
24 |
Correct |
10 ms |
700 KB |
Output is correct |
25 |
Correct |
7 ms |
344 KB |
Output is correct |
26 |
Correct |
9 ms |
600 KB |
Output is correct |
27 |
Correct |
5 ms |
344 KB |
Output is correct |
28 |
Correct |
5 ms |
344 KB |
Output is correct |
29 |
Correct |
7 ms |
344 KB |
Output is correct |
30 |
Correct |
5 ms |
344 KB |
Output is correct |
31 |
Correct |
4 ms |
344 KB |
Output is correct |
32 |
Correct |
5 ms |
344 KB |
Output is correct |
33 |
Correct |
4 ms |
344 KB |
Output is correct |
34 |
Correct |
4 ms |
344 KB |
Output is correct |
35 |
Correct |
5 ms |
596 KB |
Output is correct |
36 |
Correct |
6 ms |
608 KB |
Output is correct |
37 |
Correct |
5 ms |
344 KB |
Output is correct |
38 |
Correct |
5 ms |
440 KB |
Output is correct |
39 |
Correct |
4 ms |
600 KB |
Output is correct |
40 |
Correct |
4 ms |
600 KB |
Output is correct |
41 |
Correct |
5 ms |
344 KB |
Output is correct |
42 |
Correct |
4 ms |
344 KB |
Output is correct |
43 |
Correct |
4 ms |
344 KB |
Output is correct |
44 |
Correct |
5 ms |
344 KB |
Output is correct |
45 |
Correct |
10 ms |
344 KB |
Output is correct |
46 |
Incorrect |
0 ms |
344 KB |
Incorrect |
47 |
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 |
9 ms |
344 KB |
Output is correct |
5 |
Partially correct |
10 ms |
344 KB |
Output is partially correct |
6 |
Correct |
7 ms |
344 KB |
Output is correct |
7 |
Correct |
11 ms |
344 KB |
Output is correct |
8 |
Correct |
10 ms |
344 KB |
Output is correct |
9 |
Correct |
10 ms |
604 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 |
12 ms |
344 KB |
Output is partially correct |
13 |
Partially correct |
12 ms |
344 KB |
Output is partially correct |
14 |
Correct |
8 ms |
344 KB |
Output is correct |
15 |
Correct |
7 ms |
344 KB |
Output is correct |
16 |
Correct |
10 ms |
344 KB |
Output is correct |
17 |
Correct |
12 ms |
600 KB |
Output is correct |
18 |
Correct |
9 ms |
600 KB |
Output is correct |
19 |
Correct |
9 ms |
600 KB |
Output is correct |
20 |
Correct |
9 ms |
600 KB |
Output is correct |
21 |
Correct |
6 ms |
344 KB |
Output is correct |
22 |
Correct |
8 ms |
344 KB |
Output is correct |
23 |
Correct |
6 ms |
344 KB |
Output is correct |
24 |
Correct |
5 ms |
344 KB |
Output is correct |
25 |
Correct |
5 ms |
344 KB |
Output is correct |
26 |
Correct |
5 ms |
344 KB |
Output is correct |
27 |
Correct |
4 ms |
344 KB |
Output is correct |
28 |
Correct |
4 ms |
600 KB |
Output is correct |
29 |
Correct |
4 ms |
344 KB |
Output is correct |
30 |
Correct |
5 ms |
344 KB |
Output is correct |
31 |
Correct |
5 ms |
344 KB |
Output is correct |
32 |
Correct |
9 ms |
344 KB |
Output is correct |
33 |
Incorrect |
0 ms |
344 KB |
Incorrect |
34 |
Halted |
0 ms |
0 KB |
- |