#include <bits/stdc++.h>
#include "longesttrip.h"
using namespace std;
using ll = long long;
int n, d;
vector<int> longest_trip(int N, int D) {
n = N;
d = D;
vector<vector<int>> adj(n, vector<int>(n, 1));
vector<int> deg(n, 0), p(n, 0);
for (int i = 0;i < n;i++) {
for (int j = i + 1;j < n;j++) {
adj[i][j] = adj[j][i] = are_connected({ i }, { j });
if (adj[i][j]) deg[i]++, deg[j]++;
}
}
set<int> rem;
for (int i = 0;i < n;i++) if (deg[i] != n - 1) rem.insert(i);
queue<int> q;
for (int i = 0;i < n;i++) {
if (deg[i] == n - 1) continue;
q.push(i);
p[i] = 1;
break;
}
while (!q.empty()) {
int v = q.front();
q.pop();
vector<int> del;
for (auto& i : rem) {
if (!p[i] && !adj[v][i]) {
p[i] = 3 - p[v];
del.push_back(i);
q.push(i);
}
}
for (auto& x : del) rem.erase(x);
}
assert(rem.empty());
vector<int> r1, r2;
for (int i = 0;i < n;i++) {
if (!p[i]) p[i] = 1;
if (p[i] == 1) r1.push_back(i);
else r2.push_back(i);
}
if ((int)r1.size() == n) return r1; // Complete Graph
int s1 = r1.size(), s2 = r2.size();
for (int i = 0;i < s1;i++) {
for (int j = 0;j < s2;j++) {
if (adj[r1[i]][r2[j]]) {
swap(r1[s1 - 1], r1[i]);
swap(r2[0], r2[j]);
vector<int> ans;
for (auto& x : r1) ans.push_back(x);
for (auto& x : r2) ans.push_back(x);
return ans;
}
}
}
if ((int)r1.size() > (int)r2.size()) return r1;
return r2;
}
# |
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 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
24 ms |
344 KB |
Output is correct |
3 |
Correct |
115 ms |
340 KB |
Output is correct |
4 |
Correct |
384 ms |
344 KB |
Output is correct |
5 |
Correct |
772 ms |
676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
344 KB |
Output is correct |
2 |
Correct |
25 ms |
344 KB |
Output is correct |
3 |
Correct |
115 ms |
344 KB |
Output is correct |
4 |
Correct |
369 ms |
344 KB |
Output is correct |
5 |
Correct |
724 ms |
676 KB |
Output is correct |
6 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 6 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
344 KB |
Output is correct |
2 |
Correct |
28 ms |
344 KB |
Output is correct |
3 |
Correct |
130 ms |
344 KB |
Output is correct |
4 |
Correct |
331 ms |
344 KB |
Output is correct |
5 |
Correct |
800 ms |
676 KB |
Output is correct |
6 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 6 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
344 KB |
Output is correct |
2 |
Correct |
26 ms |
344 KB |
Output is correct |
3 |
Partially correct |
123 ms |
340 KB |
Output is partially correct |
4 |
Partially correct |
369 ms |
344 KB |
Output is partially correct |
5 |
Partially correct |
727 ms |
676 KB |
Output is partially correct |
6 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
7 |
Halted |
0 ms |
0 KB |
- |