#include "longesttrip.h"
#include <bits/stdc++.h>
#define ll int
#define pb push_back
#define ins insert
#define fr first
#define sc second
#define vll vector<ll>
#define sz size()
using namespace std;
const ll N = 260;
const ll inf = 1e9 + 7;
vector<vll> g(N);
ll d[N],p[N];
bool vis[N];
ll n;
void dfs(ll v){
vis[v] = 1;
for(auto i : g[v]){
if(d[i] != inf || (!vis[i] && d[i] < d[v] + 1))continue;
p[i] = v;
d[i] = d[v] + 1;
if(d[i] >= (n+1)/2){vis[v] = 0;return;}
dfs(i);
}
vis[v] = 0;
}
void cl(){
for(ll i=0;i<N;i++){
d[i] = inf;
p[i] = i;
}
}
pair<ll,ll> find(){
ll mx = -1, x = 0;
for(ll i=0;i<N;i++){
if(d[i] != inf && d[i] > mx){
mx = d[i];
x = i;
}
}
return {mx, x};
}
vector<int> longest_trip(int nn, int D){
ll i,j;
n=nn;
for(i=0;i<n;i++) g[i].clear();
for(i=0;i<n;i++){
for(j=i+1;j<n;j++){
if(are_connected({i},{j})){
g[i].pb(j);
g[j].pb(i);
}
}
}
ll rt = 0, ans = 0;
for(i=0;i<n;i++){
cl();
d[i] = 1;
dfs(i);
auto [mx, x] = find();
if(mx > ans){
ans = mx;
rt = i;
}
if(ans >= (n+1)/2)break;
}
auto [mx, x] = find();
vll v;
while(x != rt){
v.pb(x);
x = p[x];
}
v.pb(rt);
return v;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
344 KB |
Output is correct |
2 |
Correct |
20 ms |
344 KB |
Output is correct |
3 |
Correct |
141 ms |
344 KB |
Output is correct |
4 |
Correct |
387 ms |
496 KB |
Output is correct |
5 |
Correct |
843 ms |
1144 KB |
Output is correct |
6 |
Correct |
9 ms |
344 KB |
Output is correct |
7 |
Correct |
19 ms |
344 KB |
Output is correct |
8 |
Correct |
143 ms |
344 KB |
Output is correct |
9 |
Correct |
272 ms |
592 KB |
Output is correct |
10 |
Correct |
842 ms |
1116 KB |
Output is correct |
11 |
Correct |
818 ms |
1120 KB |
Output is correct |
12 |
Correct |
843 ms |
964 KB |
Output is correct |
13 |
Correct |
820 ms |
1028 KB |
Output is correct |
14 |
Correct |
7 ms |
344 KB |
Output is correct |
15 |
Correct |
11 ms |
344 KB |
Output is correct |
16 |
Correct |
36 ms |
344 KB |
Output is correct |
17 |
Correct |
89 ms |
344 KB |
Output is correct |
18 |
Correct |
151 ms |
344 KB |
Output is correct |
19 |
Correct |
318 ms |
712 KB |
Output is correct |
20 |
Correct |
319 ms |
592 KB |
Output is correct |
21 |
Correct |
861 ms |
728 KB |
Output is correct |
22 |
Correct |
858 ms |
920 KB |
Output is correct |
23 |
Correct |
812 ms |
736 KB |
Output is correct |
24 |
Correct |
830 ms |
728 KB |
Output is correct |
25 |
Correct |
10 ms |
344 KB |
Output is correct |
26 |
Correct |
9 ms |
344 KB |
Output is correct |
27 |
Correct |
20 ms |
344 KB |
Output is correct |
28 |
Correct |
21 ms |
344 KB |
Output is correct |
29 |
Correct |
29 ms |
344 KB |
Output is correct |
30 |
Correct |
186 ms |
344 KB |
Output is correct |
31 |
Correct |
164 ms |
600 KB |
Output is correct |
32 |
Correct |
201 ms |
344 KB |
Output is correct |
33 |
Correct |
292 ms |
480 KB |
Output is correct |
34 |
Correct |
308 ms |
592 KB |
Output is correct |
35 |
Correct |
300 ms |
600 KB |
Output is correct |
36 |
Correct |
815 ms |
776 KB |
Output is correct |
37 |
Correct |
826 ms |
1052 KB |
Output is correct |
38 |
Correct |
805 ms |
960 KB |
Output is correct |
39 |
Correct |
862 ms |
1100 KB |
Output is correct |
40 |
Correct |
840 ms |
1500 KB |
Output is correct |
41 |
Correct |
857 ms |
768 KB |
Output is correct |
42 |
Correct |
859 ms |
620 KB |
Output is correct |
43 |
Correct |
798 ms |
992 KB |
Output is correct |
44 |
Correct |
820 ms |
1212 KB |
Output is correct |
45 |
Correct |
7 ms |
344 KB |
Output is correct |
46 |
Correct |
12 ms |
344 KB |
Output is correct |
47 |
Correct |
30 ms |
344 KB |
Output is correct |
48 |
Correct |
29 ms |
344 KB |
Output is correct |
49 |
Correct |
23 ms |
344 KB |
Output is correct |
50 |
Correct |
192 ms |
344 KB |
Output is correct |
51 |
Correct |
183 ms |
600 KB |
Output is correct |
52 |
Correct |
206 ms |
1368 KB |
Output is correct |
53 |
Correct |
317 ms |
344 KB |
Output is correct |
54 |
Correct |
297 ms |
728 KB |
Output is correct |
55 |
Correct |
292 ms |
484 KB |
Output is correct |
56 |
Correct |
827 ms |
936 KB |
Output is correct |
57 |
Correct |
864 ms |
1436 KB |
Output is correct |
58 |
Correct |
789 ms |
1332 KB |
Output is correct |
59 |
Correct |
801 ms |
932 KB |
Output is correct |
60 |
Correct |
828 ms |
1328 KB |
Output is correct |
61 |
Correct |
833 ms |
776 KB |
Output is correct |
62 |
Correct |
817 ms |
648 KB |
Output is correct |
63 |
Correct |
849 ms |
1196 KB |
Output is correct |
64 |
Correct |
865 ms |
944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |