Submission #1080050

#TimeUsernameProblemLanguageResultExecution timeMemory
1080050LittleOrangeThousands Islands (IOI22_islands)C++17
10 / 100
127 ms14292 KiB
#include "islands.h" #include <variant> #include <vector> #include <bits/stdc++.h> using namespace std; using ll = int; std::variant<bool, std::vector<int>> find_journey( int n, int m, std::vector<int> u, std::vector<int> v){ if (n == 2){ vector<ll> a,b; for(ll i = 0;i<m;i++){ if (u[i]==0) a.push_back(i); else b.push_back(i); } if (a.size()<2||b.size()<1) return false; return vector<ll>({a[0],b[0],a[1],a[0],b[0],a[1]}); } if(0){ vector<ll> a(6); for(ll i = 0;i<m;i++){ if (u[i]==0&&v[i]==1) a[0] = i; if (u[i]==1&&v[i]==2) a[1] = i; if (u[i]==2&&v[i]==0) a[2] = i; if (u[i]==0&&v[i]==2) a[3] = i; if (u[i]==2&&v[i]==1) a[4] = i; if (u[i]==1&&v[i]==0) a[5] = i; } return vector<ll>({a[0],a[1],a[2],a[3],a[4],a[5],a[2],a[1],a[0],a[5],a[4],a[3]}); } if(m%2==0){ vector<vector<ll>> con(n); for(ll i = 0;i<m;i++){ con[u[i]].push_back(i); } vector<ll> inv(m); map<pair<ll,ll>,ll> mp; for(ll i = 0;i<m;i++){ mp[make_pair(u[i],v[i])] = i; } for(ll i = 0;i<m;i++){ inv[i] = mp[make_pair(v[i],u[i])]; } vector<ll> c(n,0),st; function<bool(ll,ll)> dfs; dfs = [&](ll i, ll p){ if (c[i]){ if (i==0) return true; else return false; } c[i] = 1; for(ll j : con[i]) if(v[j]!=p){ st.push_back(j); if(dfs(v[j],i)) return true; st.pop_back(); } return false; }; bool ok = dfs(0,-1); if(!ok) return false; vector<ll> ans; for(ll i : st) ans.push_back(i); reverse(st.begin(),st.end()); for(ll i : st) ans.push_back(inv[i]); for(ll i : st) ans.push_back(i); reverse(st.begin(),st.end()); for(ll i : st) ans.push_back(inv[i]); return ans; } if (n == 4){ return std::vector<int>({0, 1, 2, 4, 0, 3, 2, 1, 4, 3}); } 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...