#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, coba = 0, ti;
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";
coba++;
if(ret2.size() < ret.size())ret2 = ret;
if(coba >= 10000)ada = 2;
// 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] = ti;
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)
{
ret2.clear();
mxx = 0;
coba = 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])
{
ti++;
now = 0;
dfs2(i);
}
for(ll i = 0; i < N; i++)
{
b[i] = 0;
}
ti = 1;
vector<ll> cal;
for(ll i = 0; i < N; i++)
if(!b[i])
{
ti++;
now = 0;
dfs2(i);
if(now != mxx)
continue;
for(ll j = 0; j < N; j++)
{
if(b[j] == ti)
cal.pb(j);
}
break;
}
memset(b, 0, sizeof(b));
for(ll i = 0; i < N; i++)
{
coba = 0;
dfs(i);
ret.clear();
if(ada == 2)ada = 0;
}
return ret2;
// 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:23: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]
23 | for(ll i = 0; i < v[pos].size(); i++)
| ~~^~~~~~~~~~~~~~~
longesttrip.cpp: In function 'void dfs2(ll)':
longesttrip.cpp:37: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]
37 | for(ll i = 0; i < v[pos].size(); i++)
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3416 KB |
Output is correct |
2 |
Correct |
326 ms |
4612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
3416 KB |
Output is correct |
2 |
Correct |
64 ms |
3668 KB |
Output is correct |
3 |
Correct |
213 ms |
3840 KB |
Output is correct |
4 |
Correct |
544 ms |
4156 KB |
Output is correct |
5 |
Execution timed out |
1014 ms |
4096 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
3416 KB |
Output is correct |
2 |
Correct |
64 ms |
3416 KB |
Output is correct |
3 |
Correct |
225 ms |
3928 KB |
Output is correct |
4 |
Correct |
528 ms |
4700 KB |
Output is correct |
5 |
Correct |
997 ms |
4708 KB |
Output is correct |
6 |
Correct |
14 ms |
3416 KB |
Output is correct |
7 |
Correct |
83 ms |
3416 KB |
Output is correct |
8 |
Correct |
208 ms |
3672 KB |
Output is correct |
9 |
Correct |
414 ms |
4704 KB |
Output is correct |
10 |
Execution timed out |
1025 ms |
4340 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
3312 KB |
Output is correct |
2 |
Correct |
56 ms |
3416 KB |
Output is correct |
3 |
Correct |
222 ms |
3928 KB |
Output is correct |
4 |
Correct |
525 ms |
3692 KB |
Output is correct |
5 |
Correct |
999 ms |
4600 KB |
Output is correct |
6 |
Correct |
13 ms |
3416 KB |
Output is correct |
7 |
Correct |
74 ms |
3416 KB |
Output is correct |
8 |
Correct |
218 ms |
3672 KB |
Output is correct |
9 |
Correct |
394 ms |
3848 KB |
Output is correct |
10 |
Execution timed out |
1012 ms |
4336 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
3416 KB |
Output is correct |
2 |
Correct |
54 ms |
3416 KB |
Output is correct |
3 |
Partially correct |
195 ms |
3932 KB |
Output is partially correct |
4 |
Partially correct |
531 ms |
3684 KB |
Output is partially correct |
5 |
Partially correct |
998 ms |
4100 KB |
Output is partially correct |
6 |
Correct |
15 ms |
3416 KB |
Output is correct |
7 |
Correct |
77 ms |
3416 KB |
Output is correct |
8 |
Partially correct |
218 ms |
3936 KB |
Output is partially correct |
9 |
Partially correct |
409 ms |
3912 KB |
Output is partially correct |
10 |
Execution timed out |
1042 ms |
4496 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |