#include "longesttrip.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
using ll = int;
struct dsu{
ll c;
vector<ll> p;
dsu(ll N):c(N),p(N,-1){}
ll g(ll i){
return p[i]<0?i:p[i] = g(p[i]);
}
bool m(ll a, ll b){
a = g(a),b=g(b);
if(a==b) return false;
c--;
if(p[a]>p[b]) swap(a,b);
p[a] += p[b];
p[b] = a;
return true;
}
};
std::vector<int> longest_trip(int N, int D)
{
mt19937_64 mt(random_device{}());
ll n = N;
if (D==3){
vector<ll> r(n);
iota(r.begin(),r.end(),0);
return r;
}
vector<vector<ll>> a(n,vector<ll>(n,0));
dsu d(n);
for(ll i = 0;i<n;i++){
for(ll j = i+1;j<n;j++){
a[i][j] = a[j][i] = are_connected({i},{j});
if(a[i][j]) d.m(i,j);
}
}
if (d.c>1){
ll g = d.g(0);
for(ll i = 0;i<n;i++){
ll j = d.g(i);
if (d.p[j]<d.p[g]) g = j;
}
vector<ll> v;
for(ll i = 0;i<n;i++){
if (d.g(i)==g) v.push_back(i);
}
return v;
}
vector<ll> ret;
vector<ll> ord(n);
iota(ord.begin(),ord.end(),0);
vector<ll> cur;
cur.reserve(n);
ll cnt = 500000/max(n,10);
while(cnt--){
shuffle(ord.begin(),ord.end(),mt);
cur.push_back(ord[0]);
for(ll i : ord){
if (a[cur.back()][i]) cur.push_back(i);
}
if(cur.size()>ret.size()) ret = cur;
cur.clear();
}
return ret;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
344 KB |
Output is correct |
2 |
Incorrect |
178 ms |
700 KB |
Incorrect |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
427 ms |
344 KB |
Output is correct |
2 |
Correct |
495 ms |
344 KB |
Output is correct |
3 |
Correct |
239 ms |
344 KB |
Output is correct |
4 |
Correct |
424 ms |
484 KB |
Output is correct |
5 |
Correct |
875 ms |
684 KB |
Output is correct |
6 |
Correct |
645 ms |
344 KB |
Output is correct |
7 |
Correct |
580 ms |
340 KB |
Output is correct |
8 |
Correct |
235 ms |
344 KB |
Output is correct |
9 |
Correct |
350 ms |
344 KB |
Output is correct |
10 |
Correct |
832 ms |
704 KB |
Output is correct |
11 |
Correct |
808 ms |
684 KB |
Output is correct |
12 |
Correct |
848 ms |
684 KB |
Output is correct |
13 |
Correct |
825 ms |
692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
425 ms |
344 KB |
Output is correct |
2 |
Correct |
495 ms |
344 KB |
Output is correct |
3 |
Correct |
231 ms |
344 KB |
Output is correct |
4 |
Correct |
437 ms |
500 KB |
Output is correct |
5 |
Correct |
849 ms |
688 KB |
Output is correct |
6 |
Correct |
645 ms |
344 KB |
Output is correct |
7 |
Correct |
572 ms |
344 KB |
Output is correct |
8 |
Correct |
255 ms |
344 KB |
Output is correct |
9 |
Correct |
378 ms |
344 KB |
Output is correct |
10 |
Correct |
865 ms |
688 KB |
Output is correct |
11 |
Correct |
763 ms |
688 KB |
Output is correct |
12 |
Correct |
794 ms |
684 KB |
Output is correct |
13 |
Correct |
817 ms |
684 KB |
Output is correct |
14 |
Correct |
10 ms |
344 KB |
Output is correct |
15 |
Correct |
120 ms |
344 KB |
Output is correct |
16 |
Correct |
528 ms |
344 KB |
Output is correct |
17 |
Correct |
280 ms |
344 KB |
Output is correct |
18 |
Correct |
287 ms |
344 KB |
Output is correct |
19 |
Correct |
367 ms |
480 KB |
Output is correct |
20 |
Correct |
356 ms |
344 KB |
Output is correct |
21 |
Correct |
786 ms |
688 KB |
Output is correct |
22 |
Correct |
813 ms |
696 KB |
Output is correct |
23 |
Correct |
880 ms |
696 KB |
Output is correct |
24 |
Correct |
853 ms |
692 KB |
Output is correct |
25 |
Correct |
12 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 |
25 ms |
344 KB |
Output is correct |
29 |
Correct |
32 ms |
344 KB |
Output is correct |
30 |
Correct |
198 ms |
344 KB |
Output is correct |
31 |
Correct |
200 ms |
344 KB |
Output is correct |
32 |
Correct |
184 ms |
344 KB |
Output is correct |
33 |
Correct |
316 ms |
344 KB |
Output is correct |
34 |
Correct |
314 ms |
344 KB |
Output is correct |
35 |
Correct |
355 ms |
344 KB |
Output is correct |
36 |
Correct |
814 ms |
600 KB |
Output is correct |
37 |
Correct |
805 ms |
600 KB |
Output is correct |
38 |
Correct |
828 ms |
600 KB |
Output is correct |
39 |
Correct |
836 ms |
600 KB |
Output is correct |
40 |
Correct |
798 ms |
600 KB |
Output is correct |
41 |
Correct |
863 ms |
600 KB |
Output is correct |
42 |
Correct |
845 ms |
600 KB |
Output is correct |
43 |
Correct |
824 ms |
600 KB |
Output is correct |
44 |
Correct |
858 ms |
600 KB |
Output is correct |
45 |
Correct |
729 ms |
344 KB |
Output is correct |
46 |
Correct |
783 ms |
344 KB |
Output is correct |
47 |
Correct |
579 ms |
344 KB |
Output is correct |
48 |
Correct |
575 ms |
344 KB |
Output is correct |
49 |
Correct |
571 ms |
344 KB |
Output is correct |
50 |
Correct |
274 ms |
344 KB |
Output is correct |
51 |
Correct |
292 ms |
344 KB |
Output is correct |
52 |
Correct |
288 ms |
344 KB |
Output is correct |
53 |
Correct |
347 ms |
344 KB |
Output is correct |
54 |
Correct |
374 ms |
344 KB |
Output is correct |
55 |
Correct |
340 ms |
344 KB |
Output is correct |
56 |
Correct |
782 ms |
680 KB |
Output is correct |
57 |
Correct |
834 ms |
684 KB |
Output is correct |
58 |
Correct |
856 ms |
684 KB |
Output is correct |
59 |
Correct |
843 ms |
684 KB |
Output is correct |
60 |
Correct |
818 ms |
684 KB |
Output is correct |
61 |
Correct |
838 ms |
688 KB |
Output is correct |
62 |
Correct |
918 ms |
680 KB |
Output is correct |
63 |
Correct |
884 ms |
688 KB |
Output is correct |
64 |
Correct |
871 ms |
704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
424 ms |
344 KB |
Output is correct |
2 |
Correct |
496 ms |
344 KB |
Output is correct |
3 |
Partially correct |
252 ms |
344 KB |
Output is partially correct |
4 |
Partially correct |
443 ms |
488 KB |
Output is partially correct |
5 |
Partially correct |
809 ms |
688 KB |
Output is partially correct |
6 |
Correct |
656 ms |
344 KB |
Output is correct |
7 |
Correct |
593 ms |
344 KB |
Output is correct |
8 |
Partially correct |
281 ms |
344 KB |
Output is partially correct |
9 |
Partially correct |
403 ms |
464 KB |
Output is partially correct |
10 |
Partially correct |
834 ms |
696 KB |
Output is partially correct |
11 |
Partially correct |
871 ms |
688 KB |
Output is partially correct |
12 |
Partially correct |
835 ms |
688 KB |
Output is partially correct |
13 |
Partially correct |
880 ms |
684 KB |
Output is partially correct |
14 |
Correct |
8 ms |
344 KB |
Output is correct |
15 |
Correct |
114 ms |
344 KB |
Output is correct |
16 |
Incorrect |
148 ms |
344 KB |
Incorrect |
17 |
Halted |
0 ms |
0 KB |
- |