#include "longesttrip.h"
#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define P push
#define I insert
#define F first
#define S second
typedef long long ll;
vector<int> longest_trip(int n, int D){
if(D==3){
vector<int> tt;for(int i=0;i<n;i++)tt.PB(i);
return tt;
}
vector<int> v[n];
bool grid[n][n];
for(int i=0;i<n;i++)v[i].clear();
memset(grid,0,sizeof(grid));
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(are_connected({i},{j})){v[i].PB(j);v[j].PB(i); grid[i][j]=grid[j][i]=1;}
}
}
vector<int> v1,v2;
v1.PB(0);v2.PB(1);
for(int i=2;i<n;i++){
if(grid[i][v1.back()])v1.PB(i);
else if(grid[i][v2.back()])v2.PB(i);
else{
for(int j=v2.size()-1;j>=0;j--)v1.PB(v2[j]);
v2.clear();
v2.PB(i);
}
}
int ans=v1.size();
pair<int,int> p1={0,v1.size()-1},p2={0,0};
if(v2.size()>0){
ans=v2.size();
p1={0,0};p2={0,v2.size()-1};
}
for(int i=0;i<v1.size();i++){
int x=v1[i];
for(int j=0;j<v2.size();j++){
int y=v2[j];
if(!grid[x][y])continue;
int cur;
cur= i+1 + j+1 ;if(cur>ans){ans=cur;p1={0,i};p2={j,0};}
cur= i+1 + v2.size()-j ;if(cur>ans){ans=cur;p1={0,i};p2={j,v2.size()-1};}
cur= v1.size()-i + j+1 ;if(cur>ans){ans=cur;p1={v1.size()-1,i};p2={j,0};}
cur= v1.size()-i + v2.size()-j ;if(cur>ans){ans=cur;p1={v1.size()-1,i};p2={j,v2.size()-1};}
}
}
vector<int> ou;
for(int i=p1.F;i<=p1.S;i++)ou.PB(v1[i]);
for(int i=p2.F;i<=p2.S;i++)ou.PB(v2[i]);
return ou;
}
Compilation message
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:44:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int i=0;i<v1.size();i++){
| ~^~~~~~~~~~
longesttrip.cpp:46:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int j=0;j<v2.size();j++){
| ~^~~~~~~~~~
# |
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 |
3 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
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 |
Incorrect |
1 ms |
340 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 |
- |