# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1049361 | Zicrus | Longest Trip (IOI23_longesttrip) | C++17 | 731 ms | 1696 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 <bits/stdc++.h>
#include "longesttrip.h"
using namespace std;
typedef long long ll;
vector<vector<ll>> adj, noAdj;
vector<bool> vst;
vector<vector<ll>> k;
void dfs(ll cur, ll comp) {
vst[cur] = true;
k[comp].push_back(cur);
for (auto &e : noAdj[cur]) {
if (vst[e]) continue;
dfs(e, !comp);
}
}
vector<int> longest_trip(int n, int d) {
adj = vector<vector<ll>>(n);
noAdj = vector<vector<ll>>(n);
k = vector<vector<ll>>(2);
for (int i = 0; i < n; i++) {
for (int j = i+1; j < n; j++) {
if (are_connected({i}, {j})) {
adj[i].push_back(j);
adj[j].push_back(i);
}
else {
noAdj[i].push_back(j);
noAdj[j].push_back(i);
}
}
}
vst = vector<bool>(n);
ll comp = 0;
for (int i = 0; i < n; i++) {
if (vst[i]) continue;
dfs(i, 0);
comp = !comp;
}
if (k[0].size() < k[1].size()) swap(k[0], k[1]);
ll mxDeg = 0, bridge = 0;
for (auto &e : k[0]) {
if (adj[e].size() > mxDeg) {
mxDeg = adj[e].size();
bridge = e;
}
}
vst = vector<bool>(n);
vector<int> res;
for (auto &e : k[0]) {
vst[e] = true;
if (e == bridge) continue;
res.push_back(e);
}
res.push_back(bridge);
ll used = -1;
for (auto &e : adj[bridge]) {
if (vst[e]) continue;
res.push_back(used = e);
break;
}
if (used == -1) return res;
for (auto &e : k[1]) {
if (e == used) continue;
res.push_back(e);
}
return res;
}
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... |