#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) {
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 : 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 |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
211 ms |
952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
344 KB |
Output is correct |
2 |
Correct |
21 ms |
344 KB |
Output is correct |
3 |
Correct |
156 ms |
1472 KB |
Output is correct |
4 |
Correct |
377 ms |
580 KB |
Output is correct |
5 |
Correct |
859 ms |
988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
24 ms |
344 KB |
Output is correct |
3 |
Correct |
143 ms |
452 KB |
Output is correct |
4 |
Correct |
404 ms |
836 KB |
Output is correct |
5 |
Correct |
822 ms |
1236 KB |
Output is correct |
6 |
Correct |
6 ms |
344 KB |
Output is correct |
7 |
Correct |
22 ms |
344 KB |
Output is correct |
8 |
Correct |
142 ms |
600 KB |
Output is correct |
9 |
Correct |
355 ms |
996 KB |
Output is correct |
10 |
Correct |
858 ms |
1396 KB |
Output is correct |
11 |
Correct |
833 ms |
1404 KB |
Output is correct |
12 |
Correct |
838 ms |
1060 KB |
Output is correct |
13 |
Correct |
875 ms |
1148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
340 KB |
Output is correct |
2 |
Correct |
24 ms |
344 KB |
Output is correct |
3 |
Correct |
131 ms |
592 KB |
Output is correct |
4 |
Correct |
438 ms |
824 KB |
Output is correct |
5 |
Correct |
841 ms |
1124 KB |
Output is correct |
6 |
Correct |
8 ms |
344 KB |
Output is correct |
7 |
Correct |
17 ms |
344 KB |
Output is correct |
8 |
Correct |
132 ms |
600 KB |
Output is correct |
9 |
Correct |
301 ms |
888 KB |
Output is correct |
10 |
Correct |
851 ms |
1072 KB |
Output is correct |
11 |
Correct |
846 ms |
1144 KB |
Output is correct |
12 |
Correct |
839 ms |
1160 KB |
Output is correct |
13 |
Correct |
805 ms |
988 KB |
Output is correct |
14 |
Correct |
9 ms |
344 KB |
Output is correct |
15 |
Incorrect |
6 ms |
344 KB |
Incorrect |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
344 KB |
Output is correct |
2 |
Correct |
23 ms |
344 KB |
Output is correct |
3 |
Partially correct |
145 ms |
472 KB |
Output is partially correct |
4 |
Partially correct |
387 ms |
808 KB |
Output is partially correct |
5 |
Partially correct |
788 ms |
988 KB |
Output is partially correct |
6 |
Correct |
9 ms |
356 KB |
Output is correct |
7 |
Correct |
29 ms |
356 KB |
Output is correct |
8 |
Partially correct |
145 ms |
480 KB |
Output is partially correct |
9 |
Partially correct |
285 ms |
1020 KB |
Output is partially correct |
10 |
Partially correct |
720 ms |
1324 KB |
Output is partially correct |
11 |
Partially correct |
770 ms |
1040 KB |
Output is partially correct |
12 |
Partially correct |
848 ms |
1388 KB |
Output is partially correct |
13 |
Partially correct |
867 ms |
1132 KB |
Output is partially correct |
14 |
Correct |
6 ms |
344 KB |
Output is correct |
15 |
Incorrect |
8 ms |
344 KB |
Incorrect |
16 |
Halted |
0 ms |
0 KB |
- |