Submission #1049217

#TimeUsernameProblemLanguageResultExecution timeMemory
1049217ZicrusLongest Trip (IOI23_longesttrip)C++17
5 / 100
732 ms2208 KiB
#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; } vst = vector<bool>(n); vector<int> res; for (int i = 0; i < 1; i++) { vector<int> nw = mxRand(start); if (nw.size() > res.size()) res = nw; } return res; }

Compilation message (stderr)

longesttrip.cpp: In function 'std::vector<int> mxRand(ll)':
longesttrip.cpp:13:8: warning: unused variable 'n' [-Wunused-variable]
   13 |     ll n = adj.size();
      |        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...