#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
const int nx=305;
int qrs[nx][nx], vs[nx], m, cnt, u, v;
vector<int> d[nx];
int query(int i, int j)
{
if (i>j) swap(i, j);
return qrs[i][j];
}
void dfs(int u)
{
vs[u]=1;
cnt++;
for (auto v:d[u]) if (!vs[v]) dfs(v);
}
std::vector<int> longest_trip(int N, int D)
{
for (int i=0; i<N; i++) d[i].clear(), vs[i]=0;
for (int i=0; i<N; i++) for (int j=i+1; j<N; j++) qrs[i][j]=are_connected(vector<int> {i}, vector<int> {j});
for (int i=0; i<N; i++) for (int j=0; j<N; j++) if (query(i, j)) d[i].push_back(j);
cnt=0;
dfs(0);
vector<int> res;
if (cnt!=N)
{
if (cnt>=N-cnt) m=1;
for (int i=0; i<N; i++)
{
if (vs[i]&&m) res.push_back(i);
if (!vs[i]&&!m) res.push_back(i);
}
return res;
}
pair<int, int> mn={INT_MAX, 0};
for (int i=0; i<N; i++) mn=min(mn, {d[i].size(), i});
//cout<<"here "<<mn.first<<' '<<mn.second<<'\n';
if (mn.first>=((N-1)/2))
{
for (int i=0; i<N; i++) vs[i]=0;
int cur=mn.second;
while (1)
{
res.push_back(cur);
vs[cur]=1;
bool can=0;
for (auto v:d[u]) if (!vs[v]) can=1, cur=v;
if (!can) break;
}
return res;
}
else
{
for (int i=0; i<N; i++) if (!query(i, mn.second)&&i!=mn.second) res.push_back(i);
return res;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
344 KB |
Output is correct |
2 |
Correct |
28 ms |
344 KB |
Output is correct |
3 |
Correct |
136 ms |
856 KB |
Output is correct |
4 |
Correct |
383 ms |
1124 KB |
Output is correct |
5 |
Correct |
770 ms |
1452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
25 ms |
344 KB |
Output is correct |
3 |
Correct |
130 ms |
1112 KB |
Output is correct |
4 |
Correct |
377 ms |
1220 KB |
Output is correct |
5 |
Correct |
699 ms |
2420 KB |
Output is correct |
6 |
Incorrect |
0 ms |
344 KB |
Incorrect |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
29 ms |
708 KB |
Output is correct |
3 |
Correct |
133 ms |
856 KB |
Output is correct |
4 |
Correct |
341 ms |
1760 KB |
Output is correct |
5 |
Correct |
722 ms |
1884 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 |
32 ms |
600 KB |
Output is correct |
3 |
Partially correct |
121 ms |
1108 KB |
Output is partially correct |
4 |
Partially correct |
363 ms |
1744 KB |
Output is partially correct |
5 |
Partially correct |
696 ms |
1448 KB |
Output is partially correct |
6 |
Incorrect |
0 ms |
344 KB |
Incorrect |
7 |
Halted |
0 ms |
0 KB |
- |