Submission #1051212

#TimeUsernameProblemLanguageResultExecution timeMemory
1051212TrentThousands Islands (IOI22_islands)C++17
0 / 100
1095 ms856 KiB
#include "islands.h" #include "bits/stdc++.h" using namespace std; #define forR(i, x) for(int i = 0; i < (x); ++i) #define REP(i, a, b) for(int i = (a); i < (b); ++i) #define all(x) x.begin(), x.end() typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vll; typedef vector<bool> vb; struct edge{int t, i;}; vector<vector<edge>> adj; vi nStk, eStk; vb oStk; bool dfs(int c, vi& ans) { // nStk is [0, c), eStk is [0, c] if(oStk[c]) { for(int i : eStk) ans.push_back(i); for(int i : eStk) ans.push_back(i ^ 1); for(int i : eStk) ans.push_back(i); for(int i : eStk) ans.push_back(i ^ 1); return true; } oStk[c] = true; nStk.push_back(c); for(auto [t, i] : adj[c]) { eStk.push_back(i); if(dfs(t, ans)) return true; eStk.pop_back(); } nStk.pop_back(); oStk[c] = false; return false; } std::variant<bool, std::vector<int>> find_journey( int N, int M, std::vector<int> U, std::vector<int> V) { adj.resize(N); forR(i, M) { adj[U[i]].push_back({V[i], i}); } oStk.resize(N); vi ans; bool done = dfs(0, ans); if(done) return ans; return false; }
#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...