# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1049205 | 2024-08-08T14:53:41 Z | Zicrus | Longest Trip (IOI23_longesttrip) | C++17 | 1 ms | 392 KB |
#include <bits/stdc++.h> #include "longesttrip.h" using namespace std; typedef long long ll; vector<vector<ll>> adj; vector<bool> vst; mt19937 mt; ll sz; vector<int> mxRand(ll start) { ll n = adj.size(); ll cur = start; vector<int> res = {(int)start}; loop: vst[cur] = true; shuffle(adj[cur].begin(), adj[cur].end(), mt); for (auto &e : adj[cur]) { if (!vst[e]) { cur = e; res.push_back(e); goto loop; } } for (auto &e : res) vst[e] = false; return res; } void dfs(ll cur) { vst[cur] = true; sz++; for (auto &e : adj[cur]) { if (vst[e]) continue; dfs(e); } } vector<int> longest_trip(int n, int d) { mt = mt19937(time(0)); adj = vector<vector<ll>>(n); vst = 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); } } } sz = 0; vst = vector<bool>(n); dfs(0); bool comp0 = sz > n/2; ll start = 0; for (int i = 0; i < n; i++) { if (comp0 != vst[i]) continue; start = i; break; } for (int i = 0; i < n; i++) { if (comp0 != vst[i]) continue; if (adj[i].size() == 1) start = i; } vector<int> res; for (int i = 0; i < 50; i++) { vector<int> nw = mxRand(start); if (nw.size() > res.size()) res = nw; } return res; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 392 KB | Incorrect |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | Incorrect |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | Incorrect |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | Incorrect |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 344 KB | Incorrect |
2 | Halted | 0 ms | 0 KB | - |