#include "longesttrip.h"
#include <iostream>
#include <algorithm>
#define pii pair<int, int>
#define ff first
#define ss second
using namespace std;
vector<int> gph[404];
vector<int> longest_trip(int N, int d)
{
for(int i = 0; i < N; ++i) gph[i].clear();
for(int i = 0; i < N; ++i)
{
for(int j = i + 1; j < N; ++j)
{
if(!are_connected(vector<int>{i}, vector<int>{j}))
{
gph[i].push_back(j);
gph[j].push_back(i);
}
}
}
for(int i = 0; i < N; ++i) if((int)gph[i].size() >= (N + 1) / 2) return gph[i];
for(int i = 0; i < N; ++i) sort(gph[i].begin(), gph[i].end());
bool chc[N]{};
vector<int> ret;
ret.push_back(0), chc[0] = true;
while(1)
{
bool flag = false;
for(int i = 0; i < N; ++i) if(!chc[i] && !binary_search(gph[ret.back()].begin(), gph[ret.back()].end(), i))
{
ret.push_back(i);
chc[i] = true;
flag = true;
break;
}
if(!flag) break;
}
return ret;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
20 ms |
344 KB |
Output is correct |
3 |
Correct |
151 ms |
344 KB |
Output is correct |
4 |
Correct |
352 ms |
344 KB |
Output is correct |
5 |
Correct |
720 ms |
420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
344 KB |
Output is correct |
2 |
Correct |
26 ms |
344 KB |
Output is correct |
3 |
Correct |
126 ms |
344 KB |
Output is correct |
4 |
Correct |
383 ms |
344 KB |
Output is correct |
5 |
Correct |
769 ms |
424 KB |
Output is correct |
6 |
Incorrect |
0 ms |
344 KB |
Incorrect |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
344 KB |
Output is correct |
2 |
Correct |
26 ms |
344 KB |
Output is correct |
3 |
Correct |
123 ms |
344 KB |
Output is correct |
4 |
Correct |
353 ms |
344 KB |
Output is correct |
5 |
Correct |
742 ms |
424 KB |
Output is correct |
6 |
Correct |
8 ms |
344 KB |
Output is correct |
7 |
Correct |
34 ms |
344 KB |
Output is correct |
8 |
Correct |
107 ms |
344 KB |
Output is correct |
9 |
Correct |
247 ms |
428 KB |
Output is correct |
10 |
Correct |
705 ms |
428 KB |
Output is correct |
11 |
Correct |
734 ms |
432 KB |
Output is correct |
12 |
Correct |
714 ms |
592 KB |
Output is correct |
13 |
Correct |
716 ms |
436 KB |
Output is correct |
14 |
Correct |
8 ms |
344 KB |
Output is correct |
15 |
Correct |
13 ms |
344 KB |
Output is correct |
16 |
Correct |
33 ms |
344 KB |
Output is correct |
17 |
Correct |
75 ms |
344 KB |
Output is correct |
18 |
Correct |
118 ms |
600 KB |
Output is correct |
19 |
Correct |
265 ms |
692 KB |
Output is correct |
20 |
Correct |
279 ms |
700 KB |
Output is correct |
21 |
Correct |
712 ms |
952 KB |
Output is correct |
22 |
Correct |
722 ms |
1004 KB |
Output is correct |
23 |
Correct |
718 ms |
712 KB |
Output is correct |
24 |
Correct |
759 ms |
1224 KB |
Output is correct |
25 |
Correct |
7 ms |
344 KB |
Output is correct |
26 |
Correct |
8 ms |
344 KB |
Output is correct |
27 |
Correct |
23 ms |
344 KB |
Output is correct |
28 |
Correct |
26 ms |
344 KB |
Output is correct |
29 |
Correct |
23 ms |
344 KB |
Output is correct |
30 |
Correct |
166 ms |
448 KB |
Output is correct |
31 |
Correct |
173 ms |
956 KB |
Output is correct |
32 |
Correct |
173 ms |
960 KB |
Output is correct |
33 |
Correct |
250 ms |
600 KB |
Output is correct |
34 |
Correct |
276 ms |
688 KB |
Output is correct |
35 |
Correct |
248 ms |
856 KB |
Output is correct |
36 |
Correct |
685 ms |
436 KB |
Output is correct |
37 |
Correct |
728 ms |
856 KB |
Output is correct |
38 |
Correct |
731 ms |
1348 KB |
Output is correct |
39 |
Correct |
787 ms |
1736 KB |
Output is correct |
40 |
Correct |
771 ms |
1652 KB |
Output is correct |
41 |
Correct |
734 ms |
1112 KB |
Output is correct |
42 |
Correct |
740 ms |
1564 KB |
Output is correct |
43 |
Correct |
763 ms |
1820 KB |
Output is correct |
44 |
Correct |
714 ms |
1292 KB |
Output is correct |
45 |
Correct |
10 ms |
344 KB |
Output is correct |
46 |
Correct |
9 ms |
344 KB |
Output is correct |
47 |
Correct |
21 ms |
344 KB |
Output is correct |
48 |
Correct |
21 ms |
344 KB |
Output is correct |
49 |
Correct |
24 ms |
344 KB |
Output is correct |
50 |
Correct |
147 ms |
448 KB |
Output is correct |
51 |
Correct |
161 ms |
964 KB |
Output is correct |
52 |
Correct |
136 ms |
704 KB |
Output is correct |
53 |
Correct |
245 ms |
440 KB |
Output is correct |
54 |
Correct |
256 ms |
444 KB |
Output is correct |
55 |
Correct |
260 ms |
856 KB |
Output is correct |
56 |
Correct |
785 ms |
436 KB |
Output is correct |
57 |
Correct |
746 ms |
956 KB |
Output is correct |
58 |
Correct |
790 ms |
1556 KB |
Output is correct |
59 |
Correct |
714 ms |
1664 KB |
Output is correct |
60 |
Correct |
699 ms |
1864 KB |
Output is correct |
61 |
Correct |
711 ms |
1620 KB |
Output is correct |
62 |
Correct |
680 ms |
1284 KB |
Output is correct |
63 |
Correct |
685 ms |
1592 KB |
Output is correct |
64 |
Correct |
715 ms |
1608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
22 ms |
344 KB |
Output is correct |
3 |
Partially correct |
134 ms |
344 KB |
Output is partially correct |
4 |
Partially correct |
391 ms |
344 KB |
Output is partially correct |
5 |
Partially correct |
706 ms |
424 KB |
Output is partially correct |
6 |
Incorrect |
0 ms |
344 KB |
Incorrect |
7 |
Halted |
0 ms |
0 KB |
- |