#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 260;
vector < int > adj[maxn];
int used[maxn], edge[maxn][maxn];
int n;
void dfs(int v, int c)
{
used[v] = c;
for (int u : adj[v])
{
if (!used[u])
dfs(u, c);
}
}
int deg[maxn];
vector < int > construct(int v)
{
used[v] = 1;
vector < int > viable;
for (int u : adj[v])
if (!used[u])
viable.push_back(u);
if (viable.size() == 0)
{
vector < int > cur;
cur.push_back(v);
return cur;
}
if (viable.size() == 1)
{
vector < int > res = construct(viable[0]);
res.push_back(v);
return res;
}
vector < int > r1 = construct(viable[0]), r2;
for (int u : viable)
{
if (used[u] == 0)
r2 = construct(u);
}
vector < int > res = r1;
if (r2.size() > res.size())
res = r2;
res.push_back(v);
return res;
}
vector<int> longest_trip(int N, int D)
{
n = N;
if (n == 0)
return {};
if (D == 3)
{
vector < int > r;
for (int i = 0; i < N; i ++)
r.push_back(i);
return r;
}
for (int i = 0; i < N; i ++)
adj[i].clear();
for (int i = 0; i < N; i ++)
used[i] = 0, deg[i] = 0;
for (int i = 0; i < N; i ++)
for (int j = i + 1; j < N; j ++)
{
vector < int > a, b;
a.push_back(i);
b.push_back(j);
if (are_connected(a, b))
{
adj[i].push_back(j);
adj[j].push_back(i);
deg[i] ++;
deg[j] ++;
}
}
int cp = 0;
for (int i = 0; i < N; i ++)
{
if (!used[i])
dfs(i, ++ cp);
}
if (cp == 2)
{
vector < int > a, b;
for (int i = 0; i < N; i ++)
if (used[i] == 1)
a.push_back(i);
else
b.push_back(i);
if (a.size() > b.size())
return a;
return b;
}
for (int i = 0; i < N; i ++)
used[i] = 0;
vector < int > res = construct(0);
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
199 ms |
836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
208 KB |
Output is correct |
2 |
Correct |
31 ms |
208 KB |
Output is correct |
3 |
Correct |
178 ms |
344 KB |
Output is correct |
4 |
Correct |
461 ms |
448 KB |
Output is correct |
5 |
Correct |
913 ms |
836 KB |
Output is correct |
6 |
Incorrect |
0 ms |
208 KB |
Incorrect |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
208 KB |
Output is correct |
2 |
Correct |
29 ms |
208 KB |
Output is correct |
3 |
Correct |
169 ms |
340 KB |
Output is correct |
4 |
Correct |
409 ms |
472 KB |
Output is correct |
5 |
Correct |
880 ms |
840 KB |
Output is correct |
6 |
Correct |
11 ms |
208 KB |
Output is correct |
7 |
Correct |
31 ms |
208 KB |
Output is correct |
8 |
Correct |
156 ms |
340 KB |
Output is correct |
9 |
Correct |
316 ms |
436 KB |
Output is correct |
10 |
Correct |
692 ms |
844 KB |
Output is correct |
11 |
Correct |
888 ms |
860 KB |
Output is correct |
12 |
Correct |
901 ms |
860 KB |
Output is correct |
13 |
Correct |
919 ms |
860 KB |
Output is correct |
14 |
Correct |
10 ms |
208 KB |
Output is correct |
15 |
Correct |
15 ms |
208 KB |
Output is correct |
16 |
Correct |
50 ms |
208 KB |
Output is correct |
17 |
Correct |
68 ms |
208 KB |
Output is correct |
18 |
Correct |
147 ms |
324 KB |
Output is correct |
19 |
Correct |
312 ms |
428 KB |
Output is correct |
20 |
Correct |
287 ms |
440 KB |
Output is correct |
21 |
Correct |
773 ms |
852 KB |
Output is correct |
22 |
Correct |
763 ms |
852 KB |
Output is correct |
23 |
Correct |
901 ms |
840 KB |
Output is correct |
24 |
Correct |
818 ms |
844 KB |
Output is correct |
25 |
Correct |
15 ms |
208 KB |
Output is correct |
26 |
Correct |
14 ms |
208 KB |
Output is correct |
27 |
Correct |
29 ms |
208 KB |
Output is correct |
28 |
Correct |
39 ms |
208 KB |
Output is correct |
29 |
Correct |
36 ms |
208 KB |
Output is correct |
30 |
Correct |
226 ms |
320 KB |
Output is correct |
31 |
Correct |
183 ms |
336 KB |
Output is correct |
32 |
Correct |
193 ms |
332 KB |
Output is correct |
33 |
Correct |
221 ms |
348 KB |
Output is correct |
34 |
Correct |
342 ms |
344 KB |
Output is correct |
35 |
Correct |
330 ms |
356 KB |
Output is correct |
36 |
Correct |
895 ms |
512 KB |
Output is correct |
37 |
Correct |
831 ms |
568 KB |
Output is correct |
38 |
Correct |
987 ms |
580 KB |
Output is correct |
39 |
Correct |
871 ms |
584 KB |
Output is correct |
40 |
Correct |
821 ms |
692 KB |
Output is correct |
41 |
Correct |
881 ms |
404 KB |
Output is correct |
42 |
Correct |
931 ms |
400 KB |
Output is correct |
43 |
Correct |
758 ms |
584 KB |
Output is correct |
44 |
Correct |
941 ms |
584 KB |
Output is correct |
45 |
Correct |
7 ms |
208 KB |
Output is correct |
46 |
Correct |
10 ms |
208 KB |
Output is correct |
47 |
Correct |
31 ms |
312 KB |
Output is correct |
48 |
Correct |
28 ms |
324 KB |
Output is correct |
49 |
Correct |
27 ms |
208 KB |
Output is correct |
50 |
Correct |
280 ms |
332 KB |
Output is correct |
51 |
Correct |
184 ms |
344 KB |
Output is correct |
52 |
Correct |
242 ms |
340 KB |
Output is correct |
53 |
Correct |
317 ms |
436 KB |
Output is correct |
54 |
Correct |
275 ms |
416 KB |
Output is correct |
55 |
Correct |
285 ms |
428 KB |
Output is correct |
56 |
Correct |
802 ms |
832 KB |
Output is correct |
57 |
Correct |
860 ms |
820 KB |
Output is correct |
58 |
Correct |
820 ms |
808 KB |
Output is correct |
59 |
Correct |
805 ms |
784 KB |
Output is correct |
60 |
Correct |
845 ms |
836 KB |
Output is correct |
61 |
Correct |
834 ms |
524 KB |
Output is correct |
62 |
Correct |
919 ms |
644 KB |
Output is correct |
63 |
Correct |
847 ms |
732 KB |
Output is correct |
64 |
Correct |
727 ms |
688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
208 KB |
Output is correct |
2 |
Correct |
29 ms |
208 KB |
Output is correct |
3 |
Partially correct |
169 ms |
340 KB |
Output is partially correct |
4 |
Partially correct |
415 ms |
504 KB |
Output is partially correct |
5 |
Partially correct |
815 ms |
840 KB |
Output is partially correct |
6 |
Incorrect |
0 ms |
208 KB |
Incorrect |
7 |
Halted |
0 ms |
0 KB |
- |