#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]++;
}
}
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();
for (int i = 0;i < n;i++) {
if (!p[i] && !adj[v][i]) {
p[i] = 3 - p[v];
q.push(i);
}
}
}
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;
int s1 = r1.size(), s2 = r2.size();
bool ch = 0;
for (int i = 0;i < s1;i++) {
for (int j = 0;j < s2;j++) {
if (adj[i][j]) {
ch = 1;
swap(r1[s1 - 1], r1[i]);
swap(r2[0], r2[j]);
break;
}
}
}
if (!ch) {
if ((int)r1.size() > (int)r2.size()) return r1;
return r2;
}
vector<int> ans;
for (auto& x : r1) ans.push_back(x);
for (auto& x : r2) ans.push_back(x);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
344 KB |
Output is correct |
2 |
Correct |
22 ms |
344 KB |
Output is correct |
3 |
Correct |
122 ms |
344 KB |
Output is correct |
4 |
Correct |
375 ms |
344 KB |
Output is correct |
5 |
Correct |
698 ms |
680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
352 KB |
Output is correct |
2 |
Correct |
25 ms |
344 KB |
Output is correct |
3 |
Correct |
111 ms |
344 KB |
Output is correct |
4 |
Correct |
346 ms |
344 KB |
Output is correct |
5 |
Correct |
739 ms |
680 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 |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
21 ms |
344 KB |
Output is correct |
3 |
Correct |
116 ms |
344 KB |
Output is correct |
4 |
Correct |
353 ms |
344 KB |
Output is correct |
5 |
Correct |
751 ms |
676 KB |
Output is correct |
6 |
Incorrect |
1 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 |
23 ms |
344 KB |
Output is correct |
3 |
Partially correct |
132 ms |
344 KB |
Output is partially correct |
4 |
Partially correct |
334 ms |
344 KB |
Output is partially correct |
5 |
Partially correct |
744 ms |
676 KB |
Output is partially correct |
6 |
Incorrect |
0 ms |
344 KB |
Incorrect |
7 |
Halted |
0 ms |
0 KB |
- |