# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1007056 | 3as8 | Longest Trip (IOI23_longesttrip) | C++17 | 1 ms | 344 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>
#define ll long long
using namespace std;
bool con[300][300];
bool vis[300];
bool bkVis[300];
ll n;
ll l = 0;
void dfs(ll startIndex, vector<int>& curr) {
vis[startIndex] = true;
curr.push_back(startIndex);
bool in = false;
for(int i = 0; i < n; i++) {
if(con[startIndex][i] && !vis[i]) {
dfs(i, curr);
in = true;
}
}
if(!in) l = startIndex;
}
std::vector<int> longest_trip(int N, int D) {
n = N;
for(int i = 0; i < n; i++) {
for(int j = i + 1; j < n; j++) {
con[i][j] = con[j][i] = are_connected({i}, {j});
}
}
ll mx = LLONG_MIN;
vector<int> ans;
for(int i = 0; i < n; i++) {
if(vis[i]) continue;
for(int j = 0; j < n; j++) bkVis[j] = vis[j];
vector<int> curr;
l = i;
dfs(i, curr);
for(int j = 0; j < n; j++) vis[j] = bkVis[j];
vector<int> curr2;
dfs(l, curr2);
if(curr2.size() > ans.size()) {
ans = curr;
}
}
return ans;
}
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... |