#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "longesttrip.h"
int n;
VVI gp;
VVI edges;
VI rev(VI a) {
reverse(all(a));
return a;
}
VI longest_trip(int N, int D) {
assert(D == 1);
n = N;
gp = VVI(n);
edges = VVI(n, VI(n));
replr(i, 0, n-1) {
replr(j, i+1, n-1) {
if (are_connected({i}, {j})) {
gp[i].pb(j);
gp[j].pb(i);
edges[i][j] = edges[j][i] = true;
}
}
}
VI path1;
VI path2;
path1.pb(0);
path2.pb(1);
replr(u, 2, n-1) {
if (edges[path1.back()][u]) path1.pb(u);
else if (edges[path2.back()][u]) path2.pb(u);
else {
for (int u : rev(path2)) path1.pb(u);
path2 = VI{u};
}
}
if (edges[path2[0]][path1[0]]) {
VI ans;
for (int x : rev(path2)) ans.pb(x);
for (int x : path1) ans.pb(x);
return ans;
}
if (edges[path2.back()][path1[0]]) {
VI ans;
for (int x : path2) ans.pb(x);
for (int x : path1) ans.pb(x);
return ans;
}
/* now I know that path2 is also a cycle */
if (edges[path1.back()][path2[0]]) {
VI ans;
for (int x : path1) ans.pb(x);
for (int x : path2) ans.pb(x);
return ans;
}
/* now I know that path2 is also a cycle */
if (path1.size() > path2.size()) return path1;
return path2;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
192 ms |
1272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
344 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
344 KB |
Output is correct |
2 |
Correct |
23 ms |
344 KB |
Output is correct |
3 |
Correct |
130 ms |
456 KB |
Output is correct |
4 |
Correct |
368 ms |
580 KB |
Output is correct |
5 |
Correct |
725 ms |
980 KB |
Output is correct |
6 |
Correct |
9 ms |
344 KB |
Output is correct |
7 |
Correct |
24 ms |
344 KB |
Output is correct |
8 |
Correct |
138 ms |
592 KB |
Output is correct |
9 |
Correct |
337 ms |
600 KB |
Output is correct |
10 |
Correct |
719 ms |
1532 KB |
Output is correct |
11 |
Correct |
789 ms |
992 KB |
Output is correct |
12 |
Correct |
732 ms |
992 KB |
Output is correct |
13 |
Correct |
735 ms |
984 KB |
Output is correct |
14 |
Correct |
7 ms |
344 KB |
Output is correct |
15 |
Correct |
17 ms |
344 KB |
Output is correct |
16 |
Correct |
49 ms |
344 KB |
Output is correct |
17 |
Correct |
96 ms |
344 KB |
Output is correct |
18 |
Correct |
156 ms |
452 KB |
Output is correct |
19 |
Correct |
329 ms |
752 KB |
Output is correct |
20 |
Correct |
289 ms |
764 KB |
Output is correct |
21 |
Correct |
826 ms |
1492 KB |
Output is correct |
22 |
Correct |
838 ms |
1412 KB |
Output is correct |
23 |
Correct |
838 ms |
1276 KB |
Output is correct |
24 |
Correct |
845 ms |
1256 KB |
Output is correct |
25 |
Correct |
7 ms |
344 KB |
Output is correct |
26 |
Correct |
9 ms |
344 KB |
Output is correct |
27 |
Correct |
33 ms |
344 KB |
Output is correct |
28 |
Correct |
24 ms |
344 KB |
Output is correct |
29 |
Correct |
32 ms |
344 KB |
Output is correct |
30 |
Correct |
202 ms |
716 KB |
Output is correct |
31 |
Correct |
204 ms |
460 KB |
Output is correct |
32 |
Correct |
208 ms |
608 KB |
Output is correct |
33 |
Correct |
307 ms |
1500 KB |
Output is correct |
34 |
Correct |
337 ms |
732 KB |
Output is correct |
35 |
Correct |
307 ms |
780 KB |
Output is correct |
36 |
Correct |
846 ms |
1116 KB |
Output is correct |
37 |
Correct |
746 ms |
1124 KB |
Output is correct |
38 |
Correct |
697 ms |
1076 KB |
Output is correct |
39 |
Correct |
742 ms |
1064 KB |
Output is correct |
40 |
Correct |
813 ms |
1384 KB |
Output is correct |
41 |
Correct |
712 ms |
1048 KB |
Output is correct |
42 |
Correct |
716 ms |
1000 KB |
Output is correct |
43 |
Correct |
830 ms |
1064 KB |
Output is correct |
44 |
Correct |
824 ms |
1280 KB |
Output is correct |
45 |
Correct |
11 ms |
344 KB |
Output is correct |
46 |
Correct |
12 ms |
344 KB |
Output is correct |
47 |
Correct |
30 ms |
344 KB |
Output is correct |
48 |
Correct |
31 ms |
600 KB |
Output is correct |
49 |
Correct |
32 ms |
344 KB |
Output is correct |
50 |
Correct |
168 ms |
468 KB |
Output is correct |
51 |
Correct |
185 ms |
480 KB |
Output is correct |
52 |
Correct |
148 ms |
452 KB |
Output is correct |
53 |
Correct |
267 ms |
540 KB |
Output is correct |
54 |
Correct |
285 ms |
732 KB |
Output is correct |
55 |
Correct |
258 ms |
748 KB |
Output is correct |
56 |
Correct |
839 ms |
988 KB |
Output is correct |
57 |
Correct |
918 ms |
1144 KB |
Output is correct |
58 |
Correct |
832 ms |
1208 KB |
Output is correct |
59 |
Correct |
836 ms |
1112 KB |
Output is correct |
60 |
Correct |
807 ms |
1136 KB |
Output is correct |
61 |
Correct |
777 ms |
1268 KB |
Output is correct |
62 |
Correct |
865 ms |
992 KB |
Output is correct |
63 |
Correct |
842 ms |
1276 KB |
Output is correct |
64 |
Correct |
830 ms |
1544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
344 KB |
Output is correct |
2 |
Correct |
20 ms |
344 KB |
Output is correct |
3 |
Partially correct |
145 ms |
600 KB |
Output is partially correct |
4 |
Partially correct |
421 ms |
788 KB |
Output is partially correct |
5 |
Partially correct |
873 ms |
1516 KB |
Output is partially correct |
6 |
Correct |
7 ms |
344 KB |
Output is correct |
7 |
Correct |
25 ms |
344 KB |
Output is correct |
8 |
Partially correct |
157 ms |
344 KB |
Output is partially correct |
9 |
Partially correct |
330 ms |
776 KB |
Output is partially correct |
10 |
Partially correct |
889 ms |
1360 KB |
Output is partially correct |
11 |
Partially correct |
878 ms |
1336 KB |
Output is partially correct |
12 |
Partially correct |
842 ms |
1400 KB |
Output is partially correct |
13 |
Partially correct |
861 ms |
1220 KB |
Output is partially correct |
14 |
Correct |
5 ms |
344 KB |
Output is correct |
15 |
Correct |
14 ms |
344 KB |
Output is correct |
16 |
Incorrect |
3 ms |
344 KB |
Incorrect |
17 |
Halted |
0 ms |
0 KB |
- |