# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1052298 | 2024-08-10T13:10:48 Z | Zicrus | Longest Trip (IOI23_longesttrip) | C++17 | 760 ms | 1444 KB |
#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); vector<vector<bool>> mat(n, vector<bool>(n)); 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); mat[i][j] = true; mat[j][i] = true; } 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, comp); comp = !comp; } if (k[0].size() < k[1].size()) swap(k[0], k[1]); ll mxDeg = 0, bridge = 0; for (int i = 0; i < k[0].size(); i++) { if (adj[k[0][i]].size() > mxDeg) { mxDeg = adj[k[0][i]].size(); bridge = i; } } vst = vector<bool>(n); vector<int> res; for (int i = bridge+1; i < k[0].size(); i++) { vst[k[0][i]] = true; res.push_back(k[0][i]); } for (int i = 0; i <= bridge; i++) { vst[k[0][i]] = true; res.push_back(k[0][i]); } ll used = -1; for (auto &e : adj[k[0][bridge]]) { if (vst[e]) continue; res.push_back(used = e); break; } if (used == -1) return res; for (int i = 0; i < k[1].size(); i++) { if (k[1][i] != used) continue; used = i; break; } for (int i = 0; i < k[1].size(); i++) { if (k[1][i] == used) { used = i; break; } } for (int i = used+1; i < k[1].size(); i++) { res.push_back(k[1][i]); } for (int i = 0; i < used; i++) { res.push_back(k[1][i]); } return res; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 157 ms | 1252 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 344 KB | Output is correct |
2 | Correct | 19 ms | 344 KB | Output is correct |
3 | Correct | 91 ms | 344 KB | Output is correct |
4 | Correct | 329 ms | 592 KB | Output is correct |
5 | Correct | 685 ms | 1432 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 344 KB | Output is correct |
2 | Correct | 16 ms | 344 KB | Output is correct |
3 | Correct | 125 ms | 484 KB | Output is correct |
4 | Correct | 330 ms | 1260 KB | Output is correct |
5 | Correct | 743 ms | 1268 KB | Output is correct |
6 | Correct | 7 ms | 344 KB | Output is correct |
7 | Incorrect | 1 ms | 344 KB | Incorrect |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 344 KB | Output is correct |
2 | Correct | 17 ms | 344 KB | Output is correct |
3 | Correct | 120 ms | 344 KB | Output is correct |
4 | Correct | 305 ms | 600 KB | Output is correct |
5 | Correct | 760 ms | 1444 KB | Output is correct |
6 | Correct | 8 ms | 344 KB | Output is correct |
7 | Incorrect | 0 ms | 344 KB | Incorrect |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 344 KB | Output is correct |
2 | Correct | 22 ms | 344 KB | Output is correct |
3 | Partially correct | 118 ms | 344 KB | Output is partially correct |
4 | Partially correct | 342 ms | 576 KB | Output is partially correct |
5 | Partially correct | 722 ms | 1236 KB | Output is partially correct |
6 | Correct | 6 ms | 344 KB | Output is correct |
7 | Incorrect | 1 ms | 344 KB | Incorrect |
8 | Halted | 0 ms | 0 KB | - |