#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> longest_trip(int N, int D)
{
vector<int> path = {0};
vector<bool> inside(N, false);
inside[0] = true;
while (true) {
if (path.size() == N) {
return path;
}
bool found = false;
for (int i = 0; i < N && !found; ++i) {
if (!inside[i]) {
if (are_connected({path[0]}, {i})) {
path.insert(path.begin(), i);
found = true;
inside[i] = true;
break;
}
if (are_connected({path[path.size() - 1]}, {i})) {
path.insert(path.end(), i);
found = true;
inside[i] = true;
break;
}
for (int j = 0; j < path.size(); ++j) {
if (are_connected({path[j]}, {i})) {
vector<int> new_path;
new_path.insert(new_path.end(), path.begin() + j + 1, path.end());
new_path.insert(new_path.end(), path.begin(), path.begin() + j + 1);
path = new_path;
path.insert(path.end(), i);
found = true;
inside[i] = true;
break;
}
}
}
}
if (!found) {
if (path.size() >= (N - path.size())) {
return path;
}
path.clear();
for (int i = 0; i < N; ++i) {
if (!inside[i]) {
path.insert(path.end(), i);
}
}
return path;
}
}
}
Compilation message
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:12:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
12 | if (path.size() == N) {
| ~~~~~~~~~~~~^~~~
longesttrip.cpp:30:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for (int j = 0; j < path.size(); ++j) {
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
3 ms |
308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
208 KB |
Output is correct |
2 |
Correct |
8 ms |
208 KB |
Output is correct |
3 |
Correct |
7 ms |
208 KB |
Output is correct |
4 |
Correct |
9 ms |
208 KB |
Output is correct |
5 |
Correct |
7 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
208 KB |
Output is correct |
2 |
Correct |
10 ms |
208 KB |
Output is correct |
3 |
Correct |
9 ms |
208 KB |
Output is correct |
4 |
Correct |
7 ms |
208 KB |
Output is correct |
5 |
Correct |
9 ms |
208 KB |
Output is correct |
6 |
Correct |
11 ms |
208 KB |
Output is correct |
7 |
Correct |
10 ms |
208 KB |
Output is correct |
8 |
Correct |
6 ms |
208 KB |
Output is correct |
9 |
Correct |
10 ms |
208 KB |
Output is correct |
10 |
Correct |
10 ms |
208 KB |
Output is correct |
11 |
Correct |
9 ms |
208 KB |
Output is correct |
12 |
Correct |
10 ms |
208 KB |
Output is correct |
13 |
Correct |
10 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
208 KB |
Output is correct |
2 |
Correct |
7 ms |
208 KB |
Output is correct |
3 |
Correct |
9 ms |
208 KB |
Output is correct |
4 |
Correct |
8 ms |
208 KB |
Output is correct |
5 |
Correct |
7 ms |
208 KB |
Output is correct |
6 |
Correct |
11 ms |
208 KB |
Output is correct |
7 |
Correct |
10 ms |
208 KB |
Output is correct |
8 |
Correct |
9 ms |
208 KB |
Output is correct |
9 |
Correct |
8 ms |
208 KB |
Output is correct |
10 |
Correct |
9 ms |
208 KB |
Output is correct |
11 |
Correct |
7 ms |
208 KB |
Output is correct |
12 |
Correct |
10 ms |
208 KB |
Output is correct |
13 |
Correct |
10 ms |
208 KB |
Output is correct |
14 |
Correct |
15 ms |
208 KB |
Output is correct |
15 |
Correct |
30 ms |
208 KB |
Output is correct |
16 |
Correct |
12 ms |
208 KB |
Output is correct |
17 |
Correct |
14 ms |
208 KB |
Output is correct |
18 |
Correct |
9 ms |
208 KB |
Output is correct |
19 |
Correct |
9 ms |
304 KB |
Output is correct |
20 |
Correct |
11 ms |
208 KB |
Output is correct |
21 |
Correct |
6 ms |
208 KB |
Output is correct |
22 |
Correct |
10 ms |
208 KB |
Output is correct |
23 |
Correct |
12 ms |
208 KB |
Output is correct |
24 |
Correct |
10 ms |
308 KB |
Output is correct |
25 |
Correct |
25 ms |
208 KB |
Output is correct |
26 |
Correct |
22 ms |
208 KB |
Output is correct |
27 |
Correct |
44 ms |
240 KB |
Output is correct |
28 |
Correct |
33 ms |
208 KB |
Output is correct |
29 |
Correct |
29 ms |
208 KB |
Output is correct |
30 |
Correct |
163 ms |
208 KB |
Output is correct |
31 |
Incorrect |
877 ms |
208 KB |
too many calls |
32 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
208 KB |
Output is correct |
2 |
Correct |
9 ms |
208 KB |
Output is correct |
3 |
Correct |
6 ms |
208 KB |
Output is correct |
4 |
Correct |
9 ms |
228 KB |
Output is correct |
5 |
Correct |
8 ms |
208 KB |
Output is correct |
6 |
Correct |
8 ms |
208 KB |
Output is correct |
7 |
Correct |
10 ms |
208 KB |
Output is correct |
8 |
Correct |
8 ms |
208 KB |
Output is correct |
9 |
Correct |
9 ms |
208 KB |
Output is correct |
10 |
Correct |
8 ms |
208 KB |
Output is correct |
11 |
Correct |
7 ms |
208 KB |
Output is correct |
12 |
Correct |
10 ms |
208 KB |
Output is correct |
13 |
Correct |
9 ms |
260 KB |
Output is correct |
14 |
Correct |
18 ms |
228 KB |
Output is correct |
15 |
Correct |
23 ms |
208 KB |
Output is correct |
16 |
Correct |
12 ms |
208 KB |
Output is correct |
17 |
Correct |
11 ms |
208 KB |
Output is correct |
18 |
Correct |
11 ms |
336 KB |
Output is correct |
19 |
Correct |
9 ms |
208 KB |
Output is correct |
20 |
Correct |
5 ms |
208 KB |
Output is correct |
21 |
Correct |
17 ms |
208 KB |
Output is correct |
22 |
Correct |
15 ms |
260 KB |
Output is correct |
23 |
Correct |
40 ms |
208 KB |
Output is correct |
24 |
Correct |
26 ms |
208 KB |
Output is correct |
25 |
Correct |
30 ms |
208 KB |
Output is correct |
26 |
Partially correct |
166 ms |
208 KB |
Output is partially correct |
27 |
Incorrect |
964 ms |
332 KB |
too many calls |
28 |
Halted |
0 ms |
0 KB |
- |