#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;
bool vis[MAXN]={};
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
173 ms |
940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
344 KB |
Output is correct |
2 |
Correct |
22 ms |
344 KB |
Output is correct |
3 |
Correct |
164 ms |
344 KB |
Output is correct |
4 |
Correct |
418 ms |
760 KB |
Output is correct |
5 |
Correct |
786 ms |
872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
23 ms |
344 KB |
Output is correct |
3 |
Correct |
154 ms |
344 KB |
Output is correct |
4 |
Correct |
396 ms |
848 KB |
Output is correct |
5 |
Correct |
762 ms |
1264 KB |
Output is correct |
6 |
Correct |
6 ms |
344 KB |
Output is correct |
7 |
Incorrect |
5 ms |
344 KB |
Incorrect |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
344 KB |
Output is correct |
2 |
Correct |
32 ms |
344 KB |
Output is correct |
3 |
Correct |
144 ms |
600 KB |
Output is correct |
4 |
Correct |
363 ms |
696 KB |
Output is correct |
5 |
Correct |
828 ms |
984 KB |
Output is correct |
6 |
Correct |
8 ms |
344 KB |
Output is correct |
7 |
Correct |
17 ms |
344 KB |
Output is correct |
8 |
Correct |
146 ms |
600 KB |
Output is correct |
9 |
Correct |
312 ms |
628 KB |
Output is correct |
10 |
Correct |
805 ms |
1132 KB |
Output is correct |
11 |
Correct |
802 ms |
936 KB |
Output is correct |
12 |
Correct |
778 ms |
1192 KB |
Output is correct |
13 |
Correct |
869 ms |
880 KB |
Output is correct |
14 |
Correct |
9 ms |
344 KB |
Output is correct |
15 |
Correct |
13 ms |
344 KB |
Output is correct |
16 |
Correct |
45 ms |
344 KB |
Output is correct |
17 |
Correct |
87 ms |
444 KB |
Output is correct |
18 |
Correct |
132 ms |
948 KB |
Output is correct |
19 |
Correct |
277 ms |
500 KB |
Output is correct |
20 |
Correct |
287 ms |
708 KB |
Output is correct |
21 |
Correct |
743 ms |
796 KB |
Output is correct |
22 |
Correct |
875 ms |
1100 KB |
Output is correct |
23 |
Correct |
830 ms |
952 KB |
Output is correct |
24 |
Correct |
749 ms |
800 KB |
Output is correct |
25 |
Correct |
13 ms |
344 KB |
Output is correct |
26 |
Correct |
13 ms |
344 KB |
Output is correct |
27 |
Correct |
25 ms |
344 KB |
Output is correct |
28 |
Correct |
19 ms |
344 KB |
Output is correct |
29 |
Correct |
30 ms |
344 KB |
Output is correct |
30 |
Correct |
191 ms |
448 KB |
Output is correct |
31 |
Correct |
193 ms |
448 KB |
Output is correct |
32 |
Correct |
177 ms |
600 KB |
Output is correct |
33 |
Correct |
273 ms |
700 KB |
Output is correct |
34 |
Correct |
279 ms |
604 KB |
Output is correct |
35 |
Correct |
295 ms |
488 KB |
Output is correct |
36 |
Correct |
707 ms |
784 KB |
Output is correct |
37 |
Correct |
663 ms |
864 KB |
Output is correct |
38 |
Correct |
763 ms |
1156 KB |
Output is correct |
39 |
Correct |
762 ms |
1084 KB |
Output is correct |
40 |
Correct |
758 ms |
984 KB |
Output is correct |
41 |
Correct |
729 ms |
760 KB |
Output is correct |
42 |
Correct |
722 ms |
704 KB |
Output is correct |
43 |
Correct |
824 ms |
1052 KB |
Output is correct |
44 |
Correct |
788 ms |
1252 KB |
Output is correct |
45 |
Correct |
8 ms |
344 KB |
Output is correct |
46 |
Correct |
11 ms |
344 KB |
Output is correct |
47 |
Correct |
21 ms |
344 KB |
Output is correct |
48 |
Correct |
32 ms |
344 KB |
Output is correct |
49 |
Correct |
26 ms |
344 KB |
Output is correct |
50 |
Correct |
195 ms |
596 KB |
Output is correct |
51 |
Correct |
203 ms |
944 KB |
Output is correct |
52 |
Correct |
211 ms |
344 KB |
Output is correct |
53 |
Correct |
317 ms |
708 KB |
Output is correct |
54 |
Incorrect |
317 ms |
744 KB |
Incorrect |
55 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
25 ms |
344 KB |
Output is correct |
3 |
Partially correct |
142 ms |
456 KB |
Output is partially correct |
4 |
Partially correct |
446 ms |
600 KB |
Output is partially correct |
5 |
Partially correct |
870 ms |
956 KB |
Output is partially correct |
6 |
Correct |
10 ms |
344 KB |
Output is correct |
7 |
Incorrect |
5 ms |
344 KB |
Incorrect |
8 |
Halted |
0 ms |
0 KB |
- |