#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/2) 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/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;
}
}
# |
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 |
7 ms |
348 KB |
Output is correct |
2 |
Correct |
25 ms |
344 KB |
Output is correct |
3 |
Correct |
118 ms |
856 KB |
Output is correct |
4 |
Correct |
328 ms |
1296 KB |
Output is correct |
5 |
Correct |
783 ms |
1820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
19 ms |
344 KB |
Output is correct |
3 |
Correct |
131 ms |
724 KB |
Output is correct |
4 |
Correct |
393 ms |
1224 KB |
Output is correct |
5 |
Correct |
738 ms |
1656 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 |
22 ms |
600 KB |
Output is correct |
3 |
Correct |
120 ms |
1056 KB |
Output is correct |
4 |
Correct |
373 ms |
1624 KB |
Output is correct |
5 |
Correct |
719 ms |
1464 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 |
8 ms |
344 KB |
Output is correct |
2 |
Correct |
23 ms |
596 KB |
Output is correct |
3 |
Partially correct |
143 ms |
1228 KB |
Output is partially correct |
4 |
Partially correct |
351 ms |
1496 KB |
Output is partially correct |
5 |
Partially correct |
740 ms |
2132 KB |
Output is partially correct |
6 |
Incorrect |
0 ms |
344 KB |
Incorrect |
7 |
Halted |
0 ms |
0 KB |
- |