Submission #830675

#TimeUsernameProblemLanguageResultExecution timeMemory
830675FatihSolakThousands Islands (IOI22_islands)C++17
26 / 100
115 ms27288 KiB
#include "islands.h" #include <bits/stdc++.h> #define N 100005 using namespace std; vector<pair<int,pair<int,int>>> adj[N]; map<int,vector<int>> mp[N]; int par[N]; int par2[N]; int vis[N]; vector<int> ans; void dfs(int v,int pr){ vis[v] = 1; vector<pair<int,pair<int,int>>> tmp; for(auto u:adj[v]){ if(ans.size()) return; if(u.second.second == pr) continue; if(vis[u.first] == 2) continue; tmp.push_back(u); } if(tmp.size() > 1){ int now = v; while(now != 0){ ans.push_back(par[now]); now = par2[now]; } reverse(ans.begin(),ans.end()); ans.push_back(tmp[0].second.first); ans.push_back(tmp[0].second.second); ans.push_back(tmp[1].second.first); ans.push_back(tmp[1].second.second); ans.push_back(tmp[0].second.second); ans.push_back(tmp[0].second.first); ans.push_back(tmp[1].second.second); ans.push_back(tmp[1].second.first); now = v; while(now != 0){ ans.push_back(par[now]); now = par2[now]; } return; } else{ for(auto u:adj[v]){ if(ans.size()) return; if(vis[u.first]) continue; par[u.first] = u.second.first; par2[u.first] = v; dfs(u.first,u.second.first); } } vis[v] = 2; } variant<bool, vector<int>> find_journey(int n, int m, vector<int> U, vector<int> V){ for(int i = 0;i<m;i++){ if(mp[V[i]][U[i]].size()){ adj[U[i]].push_back({V[i],{i,mp[V[i]][U[i]].back()}}); adj[V[i]].push_back({U[i],{mp[V[i]][U[i]].back(),i}}); mp[V[i]][U[i]].pop_back(); }else{ mp[U[i]][V[i]].push_back(i); } } dfs(0,-1); if(ans.empty()) return false; 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...