#include <bits/stdc++.h>
#include "longesttrip.h"
using namespace std;
using ll = long long;
int n, d;
bool adj[256][256];
int cnt[256];
vector<int> longest_trip(int N, int D) {
n = N;
d = D;
for (int i = 0;i < n;i++) {
adj[i][i] = 1;
for (int j = i + 1;j < n;j++) {
adj[i][j] = adj[j][i] = are_connected({ i }, { j });
}
}
vector<int> a, b, g1, g2;
for (int i = 0;i < n;i++) {
if (adj[0][i]) g1.push_back(i);
else g2.push_back(i);
}
memset(cnt, 0, sizeof cnt);
for (auto& x : g1) {
for (auto& y : g2) {
if (adj[x][y]) cnt[x]++;
}
}
int mx = 0;
for (auto& x : g1) {
mx = max(mx, cnt[x]);
}
for (auto& x : g1) {
if (cnt[x] == mx) b.push_back(x);
else a.push_back(x);
}
for (auto& x : g2) b.push_back(x);
for (auto& x : a) {
for (auto& y : b) {
if (adj[x][y]) {
vector<int> ans;
for (auto& xx : a) {
if (xx != x) ans.push_back(xx);
}
ans.push_back(x);
ans.push_back(y);
for (auto& yy : b) {
if (yy != y) ans.push_back(yy);
}
return ans;
}
}
}
if (a.size() > b.size()) return a;
return b;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
18 ms |
344 KB |
Output is correct |
3 |
Correct |
118 ms |
608 KB |
Output is correct |
4 |
Correct |
336 ms |
344 KB |
Output is correct |
5 |
Correct |
750 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
344 KB |
Output is correct |
2 |
Correct |
19 ms |
344 KB |
Output is correct |
3 |
Correct |
135 ms |
344 KB |
Output is correct |
4 |
Correct |
356 ms |
344 KB |
Output is correct |
5 |
Correct |
731 ms |
600 KB |
Output is correct |
6 |
Incorrect |
0 ms |
344 KB |
Incorrect |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
344 KB |
Output is correct |
2 |
Correct |
25 ms |
344 KB |
Output is correct |
3 |
Correct |
130 ms |
344 KB |
Output is correct |
4 |
Correct |
333 ms |
600 KB |
Output is correct |
5 |
Correct |
712 ms |
488 KB |
Output is correct |
6 |
Incorrect |
0 ms |
344 KB |
Incorrect |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
344 KB |
Output is correct |
2 |
Correct |
24 ms |
596 KB |
Output is correct |
3 |
Partially correct |
122 ms |
344 KB |
Output is partially correct |
4 |
Partially correct |
333 ms |
856 KB |
Output is partially correct |
5 |
Partially correct |
753 ms |
476 KB |
Output is partially correct |
6 |
Incorrect |
0 ms |
344 KB |
Incorrect |
7 |
Halted |
0 ms |
0 KB |
- |