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();
/* for (int i = 0; i < N; i++) {
for (int j = i+1; j < N; j++) {
vector<int> tmp1 , tmp2; tmp1.push_back(i); tmp2.push_back(j);
if (are_connected(tmp1 , tmp2)) graph[i][j]=graph[j][i]=1;
}
}*/
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;
}
int s=-1;
for (int i = 0; i < N; i++) {
if (vis[i] == 0) {
s = i;
break;
}
}
if (s==-1) return ans;
memset(vis , 0 , sizeof(vis));
vis[s]=1; here=s; ans2.push_back(s);
prv=-1;
while(prv!=here) {
prv=here;
for (int i = 0; i < N; i++) {
vector<int> tmp1;
vector<int> tmp2;
if (vis[i]==0) {
tmp1.push_back(here); tmp2.push_back(i);
if (!are_connected(tmp1 , tmp2)) continue;
ans2.push_back(i);
vis[i]=1;
here=i;
break;
}
}
}
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:46:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
46 | if (ans.size() == N) return ans;
| ~~~~~~~~~~~^~~~
# | 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... |