Submission #1236789

#TimeUsernameProblemLanguageResultExecution timeMemory
1236789countlessThousands Islands (IOI22_islands)C++20
0 / 100
24 ms3396 KiB
#include "islands.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define sp <<" "<< #define endl "\n" variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) { vector<vector<pair<int, int>>> adj(N), rev(N); map<pair<int, int>, bool> done; for (int i = 0; i < M; i+=2) { int u = U[i], v = V[i]; if (u > v) swap(u, v); if (done[{u, v}]) continue; adj[U[i]].emplace_back(V[i], i); done[{u, v}] = true; } // st3 / st4 // FIND ANY CYCLE. note that for st3/4 we can just topo sort no? vector<bool> vis(N), proc(N); bool found = false; int st = -1, en = -1; vector<pair<int, int>> par(N, make_pair(-1, -1)); vector<int> path, cyc; auto dfs = [&](auto &&dfs, int u) -> void { if (found) return; vis[u] = proc[u] = true; for (auto &[v, x] : adj[u]) { if (vis[v] and proc[v]) { found = true; st = v; en = u; cyc.push_back(x); return; } if (!vis[v]) { par[v] = make_pair(u, x); dfs(dfs, v); } } proc[u] = false; }; dfs(dfs, 0); if (!found or st == -1 or en == -1) return false; int at = en; while (at != st) { cyc.push_back(par[at].second); at = par[at].first; } while (par[at].first != -1) { path.push_back(par[at].second); at = par[at].first; } // subtask 3 vector<int> ans; int n = cyc.size(), m = path.size(); for (int i = m-1; i >= 0; i--) { ans.push_back(path[i]); } for (int i = n-1; i >= 0; i--) { ans.push_back(cyc[i]); } for (int i = 0; i < n; i++) { ans.push_back(cyc[i]+1); } for (int i = 0; i < n; i++) { ans.push_back(cyc[i]); } for (int i = n-1; i >= 0; i--) { ans.push_back(cyc[i]+1); } for (int i = 0; i < m; i++) { ans.push_back(path[i]); } return ans; }
#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...