#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector <ll>;
using dll = deque <ll>;
using vi = vector <int>;
const ll MAXN = 256+16;
vll adj[MAXN];
bool mat[MAXN][MAXN];
ll tvis[MAXN];
ll timer = 1;
void dfs (ll u, ll timer, ll &c) {
if (tvis[u] == timer) return;
tvis[u] = timer;
c++;
for (ll v : adj[u]) {
dfs(v, timer, c);
}
}
vi longest_trip (int n, int d) {
timer++;
fill(adj, adj+n+5, vll({}));
for (ll u = 0; u < n; u++) {
for (ll v = 0; v < n; v++) {
mat[u][v] = false;
}
}
for (ll u = 0; u < n; u++) {
mat[u][u] = false;
for (ll v = u+1; v < n; v++) {
if (are_connected(vi({ int(u) }), vi({ int(v) }))) {
adj[u].push_back(v);
adj[v].push_back(u);
mat[u][v] = true;
mat[v][u] = true;
} else {
mat[u][v] = false;
mat[v][u] = false;
}
}
}
ll c = 0;
dfs(0, timer, c);
if (c == n) {
vi ans;
ans.push_back(0);
ll op1 = 1, op2 = 2;
while (max(op1, op2) < n) {
if (mat[ans.back()][op1]) {
ans.push_back(op1);
op1 = max(op1, op2)+1;
} else if (mat[ans.back()][op2]) {
ans.push_back(op2);
op2 = max(op1, op2)+1;
} else assert(false);
}
ans.push_back(min(op1, op2));
return ans;
} else {
if (2*c > n) { // timer is may
vi ans;
for (ll u = 0; u < n; u++) {
if (tvis[u] == timer) {
if(ans.size()) assert(mat[u][ans.back()]);
ans.push_back(u);
}
}
return ans;
} else { // timer isnt may
vi ans;
for (ll u = 0; u < n; u++) {
if (tvis[u] != timer) {
if(ans.size()) assert(mat[u][ans.back()]);
ans.push_back(u);
}
}
return ans;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Runtime error |
169 ms |
3060 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
25 ms |
344 KB |
Output is correct |
3 |
Correct |
127 ms |
856 KB |
Output is correct |
4 |
Correct |
365 ms |
1300 KB |
Output is correct |
5 |
Correct |
751 ms |
2000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
25 ms |
344 KB |
Output is correct |
3 |
Correct |
124 ms |
856 KB |
Output is correct |
4 |
Correct |
354 ms |
1332 KB |
Output is correct |
5 |
Correct |
713 ms |
1736 KB |
Output is correct |
6 |
Incorrect |
0 ms |
344 KB |
Incorrect |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
20 ms |
344 KB |
Output is correct |
3 |
Correct |
130 ms |
600 KB |
Output is correct |
4 |
Correct |
359 ms |
1040 KB |
Output is correct |
5 |
Correct |
729 ms |
1756 KB |
Output is correct |
6 |
Incorrect |
0 ms |
344 KB |
Incorrect |
7 |
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 |
Partially correct |
133 ms |
856 KB |
Output is partially correct |
4 |
Partially correct |
351 ms |
1776 KB |
Output is partially correct |
5 |
Partially correct |
752 ms |
1880 KB |
Output is partially correct |
6 |
Incorrect |
0 ms |
500 KB |
Incorrect |
7 |
Halted |
0 ms |
0 KB |
- |