#include "longesttrip.h"
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define pb push_back
const ll NN = 1e5 + 5;
vector<int> ret, ret2;
ll b[NN], n, ada = 0, mxx, now;
vector<ll> v[NN];
void dfs(ll pos)
{
if(ada)return ;
b[pos] = 1;
ret.pb(pos);
// cout << pos << " mas " << ret.size() << "_\n";
// cout << ret.size() << " dan " << mxx << "\n";
if(ret.size() * 2 >= mxx)ada = 1;
if(ada)return;
random_shuffle(v[pos].begin(), v[pos].end());
for(ll i = 0; i < v[pos].size(); i++)
{
if(b[v[pos][i]] == 0)dfs(v[pos][i]);
if(ada)return ;
}
b[pos] = 0;
// cout << pos << " kel\n";
ret.pop_back();
}
void dfs2(ll pos)
{
now++;
mxx = max(mxx, now);
b[pos] = 1;
for(ll i = 0; i < v[pos].size(); i++)
if(b[v[pos][i]] == 0)
dfs2(v[pos][i]);
}
std::vector<int> longest_trip(int N, int D)
{
mxx = 0;
ada = 0;
n = N;
ret.clear();
for(ll i = 0; i < N; i++)
{
v[i].clear();
b[i] = 0;
}
for(ll i = 0; i < N; i++)
for(ll j = i + 1; j < N; j++)
{
vector<int> A;A.pb(i);
vector<int> B;B.pb(j);
bool isi = are_connected(A, B);
if(isi)
{
// cout << i << "--" << j << "\n";
v[i].pb(j);
v[j].pb(i);
}
}
for(ll i = 0; i < N; i++)
if(!b[i])
{
now = 0;
dfs2(i);
}
for(ll i = 0; i < N; i++)
{
b[i] = 0;
}
for(ll i = 0; i < N; i++)
if(!b[i])
{
now = 0;
dfs2(i);
if(now == mxx)
{
for(ll j = 0; j < N; j++)
{
b[j] = 0;
}
dfs(i);
return ret;
}
}
// return ret;
// ll mul = 1;
// if(N % 2 == 0)
// {
// vector<int> A;A.pb(0);
// vector<int> B;B.pb(1);
// bool isi = are_connected(A, B);
// if(!isi)
// swap(cal[1], cal[2]);
// ret.pb(cal[0]);
// ret.pb(cal[1]);
// }
// else
// ret.pb(cal[0]);
// for(ll i = mul; i + 1 < N; i += 2)
// {
// ll now = ret.back();
// vector<int> A;A.pb(now);
// vector<int> B;A.pb(cal[i]);
// bool isi = are_connected(A, B);
// if()
// }
// return ret;
}
Compilation message
longesttrip.cpp: In function 'void dfs(ll)':
longesttrip.cpp:17:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
17 | if(ret.size() * 2 >= mxx)ada = 1;
| ~~~~~~~~~~~~~~~^~~~~~
longesttrip.cpp:20:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for(ll i = 0; i < v[pos].size(); i++)
| ~~^~~~~~~~~~~~~~~
longesttrip.cpp: In function 'void dfs2(ll)':
longesttrip.cpp:34:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(ll i = 0; i < v[pos].size(); i++)
| ~~^~~~~~~~~~~~~~~
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:110:1: warning: control reaches end of non-void function [-Wreturn-type]
110 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2648 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2904 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2648 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2648 KB |
Output is correct |
2 |
Correct |
27 ms |
2648 KB |
Output is correct |
3 |
Correct |
121 ms |
2900 KB |
Output is correct |
4 |
Correct |
328 ms |
3388 KB |
Output is correct |
5 |
Correct |
781 ms |
3928 KB |
Output is correct |
6 |
Correct |
7 ms |
2648 KB |
Output is correct |
7 |
Correct |
21 ms |
2648 KB |
Output is correct |
8 |
Correct |
116 ms |
2904 KB |
Output is correct |
9 |
Correct |
276 ms |
3416 KB |
Output is correct |
10 |
Correct |
741 ms |
4008 KB |
Output is correct |
11 |
Correct |
721 ms |
4260 KB |
Output is correct |
12 |
Correct |
702 ms |
3908 KB |
Output is correct |
13 |
Correct |
737 ms |
4288 KB |
Output is correct |
14 |
Correct |
7 ms |
2648 KB |
Output is correct |
15 |
Correct |
10 ms |
2648 KB |
Output is correct |
16 |
Correct |
35 ms |
2904 KB |
Output is correct |
17 |
Correct |
68 ms |
2904 KB |
Output is correct |
18 |
Correct |
119 ms |
3160 KB |
Output is correct |
19 |
Correct |
256 ms |
3416 KB |
Output is correct |
20 |
Correct |
248 ms |
3420 KB |
Output is correct |
21 |
Correct |
725 ms |
4420 KB |
Output is correct |
22 |
Correct |
748 ms |
4260 KB |
Output is correct |
23 |
Correct |
734 ms |
4548 KB |
Output is correct |
24 |
Correct |
698 ms |
4252 KB |
Output is correct |
25 |
Correct |
8 ms |
2644 KB |
Output is correct |
26 |
Correct |
10 ms |
2648 KB |
Output is correct |
27 |
Correct |
21 ms |
2648 KB |
Output is correct |
28 |
Correct |
20 ms |
2648 KB |
Output is correct |
29 |
Correct |
22 ms |
2648 KB |
Output is correct |
30 |
Correct |
148 ms |
3564 KB |
Output is correct |
31 |
Correct |
159 ms |
3576 KB |
Output is correct |
32 |
Correct |
154 ms |
3048 KB |
Output is correct |
33 |
Correct |
228 ms |
3848 KB |
Output is correct |
34 |
Correct |
258 ms |
3672 KB |
Output is correct |
35 |
Correct |
242 ms |
3408 KB |
Output is correct |
36 |
Correct |
741 ms |
3596 KB |
Output is correct |
37 |
Correct |
733 ms |
4104 KB |
Output is correct |
38 |
Correct |
764 ms |
3908 KB |
Output is correct |
39 |
Correct |
678 ms |
4328 KB |
Output is correct |
40 |
Correct |
742 ms |
4360 KB |
Output is correct |
41 |
Correct |
715 ms |
3808 KB |
Output is correct |
42 |
Correct |
745 ms |
3608 KB |
Output is correct |
43 |
Correct |
700 ms |
4500 KB |
Output is correct |
44 |
Correct |
713 ms |
4064 KB |
Output is correct |
45 |
Correct |
11 ms |
2648 KB |
Output is correct |
46 |
Correct |
10 ms |
2648 KB |
Output is correct |
47 |
Correct |
23 ms |
2904 KB |
Output is correct |
48 |
Correct |
25 ms |
2648 KB |
Output is correct |
49 |
Correct |
21 ms |
2904 KB |
Output is correct |
50 |
Correct |
169 ms |
3304 KB |
Output is correct |
51 |
Execution timed out |
2264 ms |
3560 KB |
Time limit exceeded |
52 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2648 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |