#include "longesttrip.h"
#define sz(v) (int) v.size()
#define ff first
#define ss second
using namespace std;
typedef pair<int,int> ii;
vector<int> longest_trip(int N, int D)
{
vector<vector<bool>> A(N);
for(int i = 0; i < N; ++i) A[i].resize(N);
for(int i = 0; i < N; ++i){
for(int j = 0; j < i; ++j){
A[i][j] = are_connected({i},{j});
A[j][i] = A[i][j];
}
}
vector<int> G(N);
for(int i = 0; i < N; ++i){
for(int j = 0; j < N; ++j) if(A[i][j]) G[i]++;
}
int x = 0;
for(int i = 1; i < N; ++i){
if(G[i] < G[x]) x = i;
}
vector<int> ans;
if(G[x] <= (N/2)-1){
for(int i = 0; i < N; ++i){
if((i == x) || A[x][i]) continue;
ans.push_back(i);
}
return ans;
}
// G[x] >= (N/2) -> G[i] >= (N/2) for all 0 <= i < N
vector<bool> T(N,false);
ans = {0};
T[0] = 1;
int last = 0;
for(int i = 1; i < (N+1)/2; ++i){
for(int j = 0; j < N; ++j){
if(T[j] || !A[last][j] || (j == last)) continue;
// j is not in ans, j is adjacent to last, j is not last
ans.push_back(j);
last = j;
T[j] = 1;
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
208 KB |
Output is correct |
2 |
Correct |
36 ms |
208 KB |
Output is correct |
3 |
Correct |
162 ms |
208 KB |
Output is correct |
4 |
Correct |
410 ms |
280 KB |
Output is correct |
5 |
Correct |
901 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
208 KB |
Output is correct |
2 |
Correct |
31 ms |
208 KB |
Output is correct |
3 |
Correct |
191 ms |
208 KB |
Output is correct |
4 |
Correct |
393 ms |
208 KB |
Output is correct |
5 |
Execution timed out |
1055 ms |
208 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
208 KB |
Output is correct |
2 |
Correct |
26 ms |
208 KB |
Output is correct |
3 |
Correct |
207 ms |
208 KB |
Output is correct |
4 |
Correct |
380 ms |
276 KB |
Output is correct |
5 |
Correct |
918 ms |
208 KB |
Output is correct |
6 |
Correct |
8 ms |
208 KB |
Output is correct |
7 |
Correct |
28 ms |
208 KB |
Output is correct |
8 |
Correct |
193 ms |
208 KB |
Output is correct |
9 |
Correct |
370 ms |
208 KB |
Output is correct |
10 |
Correct |
956 ms |
208 KB |
Output is correct |
11 |
Correct |
750 ms |
208 KB |
Output is correct |
12 |
Correct |
757 ms |
208 KB |
Output is correct |
13 |
Correct |
855 ms |
208 KB |
Output is correct |
14 |
Correct |
11 ms |
248 KB |
Output is correct |
15 |
Correct |
17 ms |
208 KB |
Output is correct |
16 |
Correct |
32 ms |
208 KB |
Output is correct |
17 |
Correct |
129 ms |
208 KB |
Output is correct |
18 |
Correct |
109 ms |
208 KB |
Output is correct |
19 |
Correct |
388 ms |
208 KB |
Output is correct |
20 |
Correct |
373 ms |
208 KB |
Output is correct |
21 |
Correct |
968 ms |
208 KB |
Output is correct |
22 |
Execution timed out |
1024 ms |
208 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
208 KB |
Output is correct |
2 |
Correct |
38 ms |
208 KB |
Output is correct |
3 |
Partially correct |
129 ms |
208 KB |
Output is partially correct |
4 |
Partially correct |
338 ms |
328 KB |
Output is partially correct |
5 |
Partially correct |
916 ms |
208 KB |
Output is partially correct |
6 |
Incorrect |
0 ms |
208 KB |
Incorrect |
7 |
Halted |
0 ms |
0 KB |
- |