#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
const int nx=305;
int qrs[nx][nx], vs[nx], m, cnt, u, v, r[nx], st, ed, p;
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;
}
st=ed=0;
queue<pair<int, int>> q;
q.push({0, 0});
for (int i=0; i<N;i ++) vs[i]=0;
vs[0]=1;
while (!q.empty())
{
auto [u, p]=q.front();
if (u!=0)
{
if (query(u, st)) r[u]=st, st=u;
else if (query(u, ed)) r[ed]=u, ed=u;
else
{
r[ed]=st;
r[u]=p;
st=u;
}
}
q.pop();
for (auto v:d[u])
{
if (!vs[v]) vs[v]=1, q.push({v, u});
}
}
while (st!=ed) res.push_back(st), st=r[st];
res.push_back(ed);
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
183 ms |
2132 KB |
Incorrect |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
600 KB |
Output is correct |
2 |
Correct |
23 ms |
600 KB |
Output is correct |
3 |
Correct |
142 ms |
1216 KB |
Output is correct |
4 |
Correct |
342 ms |
1260 KB |
Output is correct |
5 |
Correct |
712 ms |
1700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
344 KB |
Output is correct |
2 |
Correct |
29 ms |
596 KB |
Output is correct |
3 |
Correct |
120 ms |
1368 KB |
Output is correct |
4 |
Correct |
360 ms |
1368 KB |
Output is correct |
5 |
Correct |
761 ms |
2124 KB |
Output is correct |
6 |
Correct |
6 ms |
344 KB |
Output is correct |
7 |
Correct |
24 ms |
344 KB |
Output is correct |
8 |
Correct |
135 ms |
1112 KB |
Output is correct |
9 |
Correct |
290 ms |
856 KB |
Output is correct |
10 |
Correct |
720 ms |
1896 KB |
Output is correct |
11 |
Correct |
696 ms |
2104 KB |
Output is correct |
12 |
Correct |
732 ms |
2080 KB |
Output is correct |
13 |
Correct |
742 ms |
1652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
344 KB |
Output is correct |
2 |
Correct |
22 ms |
344 KB |
Output is correct |
3 |
Correct |
149 ms |
1152 KB |
Output is correct |
4 |
Correct |
346 ms |
1492 KB |
Output is correct |
5 |
Correct |
733 ms |
1408 KB |
Output is correct |
6 |
Correct |
8 ms |
344 KB |
Output is correct |
7 |
Correct |
30 ms |
600 KB |
Output is correct |
8 |
Correct |
133 ms |
1368 KB |
Output is correct |
9 |
Correct |
279 ms |
1028 KB |
Output is correct |
10 |
Correct |
724 ms |
2056 KB |
Output is correct |
11 |
Correct |
772 ms |
1664 KB |
Output is correct |
12 |
Correct |
741 ms |
1920 KB |
Output is correct |
13 |
Correct |
786 ms |
1404 KB |
Output is correct |
14 |
Correct |
7 ms |
344 KB |
Output is correct |
15 |
Incorrect |
1 ms |
344 KB |
Incorrect |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
596 KB |
Output is correct |
2 |
Correct |
26 ms |
600 KB |
Output is correct |
3 |
Partially correct |
133 ms |
1112 KB |
Output is partially correct |
4 |
Partially correct |
371 ms |
1260 KB |
Output is partially correct |
5 |
Partially correct |
731 ms |
1440 KB |
Output is partially correct |
6 |
Correct |
6 ms |
344 KB |
Output is correct |
7 |
Correct |
25 ms |
600 KB |
Output is correct |
8 |
Partially correct |
128 ms |
1104 KB |
Output is partially correct |
9 |
Partially correct |
299 ms |
720 KB |
Output is partially correct |
10 |
Partially correct |
739 ms |
1684 KB |
Output is partially correct |
11 |
Partially correct |
734 ms |
1844 KB |
Output is partially correct |
12 |
Partially correct |
744 ms |
1456 KB |
Output is partially correct |
13 |
Partially correct |
747 ms |
1720 KB |
Output is partially correct |
14 |
Incorrect |
0 ms |
344 KB |
Incorrect |
15 |
Halted |
0 ms |
0 KB |
- |