# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1046804 | sonamoo | Longest Trip (IOI23_longesttrip) | C++17 | 767 ms | 848 KiB |
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++) {
if (vis[i]==0 && graph[here][i]==1) {
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++) {
if (vis[i]==0 && graph[here][i]==1) {
ans2.push_back(i);
vis[i]=1;
here=i;
break;
}
}
}
if (ans2.size() < ans.size()) return ans;
return ans2;
}
Compilation message (stderr)
# | 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... |