#include "longesttrip.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
using ll = int;
std::vector<int> longest_trip(int N, int D)
{
mt19937_64 mt(random_device{}());
ll t0 = time(0);
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));
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});
}
}
vector<ll> vis(n,0);
vector<ll> ret;
vector<ll> ord(n);
iota(ord.begin(),ord.end(),0);
auto it = ord.begin();
vector<ll> cur;
function<void(ll)> dfs;
dfs = [&](ll i){
cur.push_back(i);
vis[i] = 1;
for(;it!=ord.end();it++){
ll j = *it;
if(a[i][j]&&!vis[j]){
dfs(j);
return;
}
}
};
ll cnt = 10000;
while(cnt--){
shuffle(ord.begin(),ord.end(),mt);
it = ord.begin();
dfs(ord[0]);
if(cur.size()>ret.size()) ret = cur;
cur.clear();
fill(vis.begin(),vis.end(),0);
}
return ret;
}
Compilation message
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:11:8: warning: unused variable 't0' [-Wunused-variable]
11 | ll t0 = time(0);
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Incorrect |
206 ms |
688 KB |
Incorrect |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
189 ms |
344 KB |
Output is correct |
2 |
Correct |
187 ms |
344 KB |
Output is correct |
3 |
Correct |
314 ms |
344 KB |
Output is correct |
4 |
Correct |
561 ms |
592 KB |
Output is correct |
5 |
Correct |
992 ms |
684 KB |
Output is correct |
6 |
Correct |
195 ms |
344 KB |
Output is correct |
7 |
Correct |
196 ms |
344 KB |
Output is correct |
8 |
Correct |
288 ms |
344 KB |
Output is correct |
9 |
Correct |
393 ms |
460 KB |
Output is correct |
10 |
Correct |
877 ms |
684 KB |
Output is correct |
11 |
Correct |
997 ms |
852 KB |
Output is correct |
12 |
Correct |
998 ms |
684 KB |
Output is correct |
13 |
Correct |
1000 ms |
688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
171 ms |
344 KB |
Output is correct |
2 |
Correct |
181 ms |
344 KB |
Output is correct |
3 |
Correct |
306 ms |
344 KB |
Output is correct |
4 |
Correct |
545 ms |
344 KB |
Output is correct |
5 |
Correct |
967 ms |
684 KB |
Output is correct |
6 |
Correct |
191 ms |
344 KB |
Output is correct |
7 |
Correct |
191 ms |
344 KB |
Output is correct |
8 |
Correct |
313 ms |
344 KB |
Output is correct |
9 |
Correct |
506 ms |
464 KB |
Output is correct |
10 |
Execution timed out |
1004 ms |
852 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
180 ms |
344 KB |
Output is correct |
2 |
Correct |
181 ms |
344 KB |
Output is correct |
3 |
Partially correct |
319 ms |
344 KB |
Output is partially correct |
4 |
Partially correct |
585 ms |
488 KB |
Output is partially correct |
5 |
Execution timed out |
1033 ms |
688 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |