#include <vector>
#include <set>
#include "longesttrip.h"
#include <bitset>
using namespace std;
int const MAXN=256;
vector<int>nei[MAXN]={};
vector<int>ans;
vector<int>cur;
bitset<MAXN>vis;
int root=0;
vector<int> dfs(int u)
{
vis[u]=1;
vector<int>mx,mx1;
for (auto i:nei[u])
{
if (vis[i])
continue;
vector<int>z=dfs(i);
if (z.size()>mx.size())
{
mx1=mx;
mx=z;
}
else if (z.size()>mx1.size())
mx1=z;
}
if (u==root)
{
vector<int>f=mx;
f.push_back(u);
for (auto i:mx1)
f.push_back(i);
if (f.size()>ans.size())
ans=f;
return f;
}
mx.push_back(u);
return mx;
}
vector<int> longest_trip(int N, int D)
{
ans.clear();
for (int i=0;i<N;i++)
nei[i].clear(),vis[i]=0;;
vector<int>x,y;
for (int i=0;i<N;i++)
for (int j=i+1;j<N;j++)
{
if (are_connected({i},{j}))
nei[i].push_back(j),nei[j].push_back(i);
}
for (int i=0;i<N;i++)
{
if (!vis[i])
{
root=i;
dfs(i);
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
204 ms |
732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
344 KB |
Output is correct |
2 |
Correct |
22 ms |
344 KB |
Output is correct |
3 |
Correct |
158 ms |
600 KB |
Output is correct |
4 |
Correct |
394 ms |
460 KB |
Output is correct |
5 |
Correct |
858 ms |
788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
21 ms |
344 KB |
Output is correct |
3 |
Correct |
157 ms |
600 KB |
Output is correct |
4 |
Correct |
404 ms |
672 KB |
Output is correct |
5 |
Correct |
852 ms |
848 KB |
Output is correct |
6 |
Correct |
11 ms |
344 KB |
Output is correct |
7 |
Incorrect |
5 ms |
344 KB |
Incorrect |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
344 KB |
Output is correct |
2 |
Correct |
22 ms |
344 KB |
Output is correct |
3 |
Correct |
171 ms |
344 KB |
Output is correct |
4 |
Correct |
306 ms |
940 KB |
Output is correct |
5 |
Correct |
806 ms |
1100 KB |
Output is correct |
6 |
Correct |
8 ms |
344 KB |
Output is correct |
7 |
Correct |
25 ms |
344 KB |
Output is correct |
8 |
Correct |
118 ms |
600 KB |
Output is correct |
9 |
Correct |
281 ms |
468 KB |
Output is correct |
10 |
Correct |
832 ms |
880 KB |
Output is correct |
11 |
Correct |
808 ms |
1264 KB |
Output is correct |
12 |
Correct |
812 ms |
768 KB |
Output is correct |
13 |
Correct |
851 ms |
916 KB |
Output is correct |
14 |
Correct |
8 ms |
344 KB |
Output is correct |
15 |
Correct |
15 ms |
344 KB |
Output is correct |
16 |
Correct |
42 ms |
344 KB |
Output is correct |
17 |
Correct |
92 ms |
344 KB |
Output is correct |
18 |
Correct |
150 ms |
456 KB |
Output is correct |
19 |
Correct |
318 ms |
592 KB |
Output is correct |
20 |
Correct |
297 ms |
344 KB |
Output is correct |
21 |
Correct |
837 ms |
944 KB |
Output is correct |
22 |
Correct |
830 ms |
768 KB |
Output is correct |
23 |
Correct |
834 ms |
1020 KB |
Output is correct |
24 |
Correct |
872 ms |
1072 KB |
Output is correct |
25 |
Correct |
8 ms |
344 KB |
Output is correct |
26 |
Correct |
9 ms |
344 KB |
Output is correct |
27 |
Correct |
22 ms |
344 KB |
Output is correct |
28 |
Correct |
23 ms |
344 KB |
Output is correct |
29 |
Correct |
32 ms |
344 KB |
Output is correct |
30 |
Correct |
184 ms |
344 KB |
Output is correct |
31 |
Correct |
215 ms |
344 KB |
Output is correct |
32 |
Correct |
193 ms |
344 KB |
Output is correct |
33 |
Correct |
311 ms |
848 KB |
Output is correct |
34 |
Correct |
332 ms |
684 KB |
Output is correct |
35 |
Correct |
343 ms |
600 KB |
Output is correct |
36 |
Correct |
861 ms |
760 KB |
Output is correct |
37 |
Correct |
866 ms |
1004 KB |
Output is correct |
38 |
Correct |
865 ms |
1192 KB |
Output is correct |
39 |
Correct |
829 ms |
1092 KB |
Output is correct |
40 |
Correct |
839 ms |
1476 KB |
Output is correct |
41 |
Correct |
842 ms |
1204 KB |
Output is correct |
42 |
Correct |
783 ms |
852 KB |
Output is correct |
43 |
Correct |
703 ms |
1216 KB |
Output is correct |
44 |
Correct |
807 ms |
1456 KB |
Output is correct |
45 |
Correct |
9 ms |
344 KB |
Output is correct |
46 |
Correct |
8 ms |
344 KB |
Output is correct |
47 |
Correct |
16 ms |
344 KB |
Output is correct |
48 |
Correct |
23 ms |
344 KB |
Output is correct |
49 |
Correct |
24 ms |
344 KB |
Output is correct |
50 |
Correct |
169 ms |
432 KB |
Output is correct |
51 |
Correct |
177 ms |
592 KB |
Output is correct |
52 |
Correct |
184 ms |
344 KB |
Output is correct |
53 |
Correct |
319 ms |
500 KB |
Output is correct |
54 |
Incorrect |
353 ms |
500 KB |
Incorrect |
55 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
23 ms |
344 KB |
Output is correct |
3 |
Partially correct |
137 ms |
344 KB |
Output is partially correct |
4 |
Partially correct |
410 ms |
600 KB |
Output is partially correct |
5 |
Partially correct |
863 ms |
1296 KB |
Output is partially correct |
6 |
Correct |
8 ms |
344 KB |
Output is correct |
7 |
Incorrect |
5 ms |
344 KB |
Incorrect |
8 |
Halted |
0 ms |
0 KB |
- |