This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> ans , ans2;
int vis[260];
int graph[260][260];
void init() {
ans.clear();
ans2.clear();
memset(graph , 0 , sizeof(graph));
memset(vis , 0 , sizeof(vis));
}
vector<int> longest_trip(int N, int D) {
init();
int here = 0; vis[0]=1;
ans.push_back(0);
int prv=-1;
while(prv!=here) {
prv=here;
for (int i = 0; i < N; i++) {
vector<int> tmp1 , tmp2;
if (vis[i]==0) {
tmp1.push_back(i);
tmp2.push_back(here);
if (!are_connected(tmp1 , tmp2)) continue;
ans.push_back(i);
vis[i]=1;
here=i;
break;
}
}
}
if (D == 2) {
if (ans.size() == N) return ans;
reverse(ans.begin() , ans.end());
for (int i = 0; i < N; i++) if (vis[i]==0) ans.push_back(i);
return ans;
}
if (D == 3) {
for (int i = 0; i < N; i++) ans2.push_back(i);
return ans2;
}
for (int i = 0; i < N; i++) if (vis[i] == 0) ans2.push_back(i);
for (int i = 0; i < ans2.size(); i++) {
vector<int> tmp1 , tmp2;
tmp1.push_back(ans[0]);
tmp2.push_back(ans2[i]);
if (are_connected(tmp1 , tmp2)) {
vector<int> ANS;
for (int j = 0; j < ans2.size(); j++) if (j != i) ANS.push_back(ans2[j]);
ANS.push_back(ans2[i]);
for (auto t : ans) ANS.push_back(t);
return ANS;
}
}
for (int i = 1; i < ans.size()-1; i++) {
for (int j = 0; j < ans2.size(); j++) {
vector<int> tmp1 , tmp2;
tmp1.push_back(ans[i]);
tmp2.push_back(ans2[j]);
if (are_connected(tmp1 , tmp2)) {
vector<int> ANS;
for (int k = 0; k < ans2.size(); k++) if (k != j) ANS.push_back(ans2[k]);
ANS.push_back(ans2[j]);
for (int k = i; k < ans.size(); k++) ANS.push_back(ans[k]);
for (int k = 0; k < i; k++) ANS.push_back(ans[k]);
return ANS;
}
}
}
if (ans2.size() < ans.size()) return ans;
return ans2;
}
Compilation message (stderr)
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:40:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
40 | if (ans.size() == N) return ans;
| ~~~~~~~~~~~^~~~
longesttrip.cpp:53:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (int i = 0; i < ans2.size(); i++) {
| ~~^~~~~~~~~~~~~
longesttrip.cpp:59:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for (int j = 0; j < ans2.size(); j++) if (j != i) ANS.push_back(ans2[j]);
| ~~^~~~~~~~~~~~~
longesttrip.cpp:66:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for (int i = 1; i < ans.size()-1; i++) {
| ~~^~~~~~~~~~~~~~
longesttrip.cpp:67:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for (int j = 0; j < ans2.size(); j++) {
| ~~^~~~~~~~~~~~~
longesttrip.cpp:73:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for (int k = 0; k < ans2.size(); k++) if (k != j) ANS.push_back(ans2[k]);
| ~~^~~~~~~~~~~~~
longesttrip.cpp:75:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | for (int k = i; k < ans.size(); k++) ANS.push_back(ans[k]);
| ~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |