Submission #1058460

#TimeUsernameProblemLanguageResultExecution timeMemory
1058460tolbiThousands Islands (IOI22_islands)C++17
12.35 / 100
21 ms4788 KiB
#include "islands.h" #include <bits/stdc++.h> using namespace std; std::variant<bool, std::vector<int>> find_journey( int N, int M, std::vector<int> U, std::vector<int> V) { vector<vector<pair<int,int>>> arr(N); for (int i = 0; i < M; i++){ arr[U[i]].push_back({V[i],i}); } for (int i = 0; i < N; ++i) { sort(arr[i].begin(), arr[i].end()); } if (arr[0].size()==0) { return false; } if (arr[0].size()>=2){ int a = arr[0][0].first; int b = arr[0][1].first; if (a==b){ return vector<int>{arr[0][0].second,arr[a][0].second,arr[0][1].second,arr[0][0].second,arr[a][0].second,arr[0][1].second}; } else { return vector<int>{ arr[0][0].second, arr[a][0].second, arr[0][1].second, arr[b][0].second, arr[a][0].second, arr[0][0].second, arr[b][0].second, arr[0][1].second }; } } vector<bool> vis(N,false); vector<pair<int,int>> par(N,{-1,-1}); function<void(int)> dfs = [&](int node)->void{ if (vis[node]) return; vis[node]=true; for (auto it : arr[node]){ if (vis[it.first]) continue; par[it.first]={node,it.second}; dfs(it.first); } }; dfs(0); for (int i = 1; i < N; i++){ if (arr[i].size()>=3 && vis[i]){ vector<int> ans; int nd = i; while (nd!=-1){ ans.push_back(par[nd].second); nd=par[nd].first; } reverse(ans.begin(), ans.end()); sort(arr[i].begin(), arr[i].end(), [&](pair<int,int> a, pair<int,int> b){ return (par[i].second^1^a.second)>(par[i].second^1^b.second); }); ans.push_back(arr[i][0].second); ans.push_back(arr[i][0].second^1); ans.push_back(arr[i][1].second); ans.push_back(arr[i][1].second^1); ans.push_back(arr[i][0].second^1); ans.push_back(arr[i][0].second); ans.push_back(arr[i][1].second^1); ans.push_back(arr[i][1].second); nd = i; while (nd!=-1){ ans.push_back(par[nd].second); nd=par[nd].first; } 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...