Submission #939736

#TimeUsernameProblemLanguageResultExecution timeMemory
939736Trisanu_DasThousands Islands (IOI22_islands)C++17
24 / 100
36 ms8844 KiB
#include "islands.h" #include<bits/stdc++.h> using namespace std; const int N=1e5+5; const int M=2e5+5; int n,m; vector<pair<int,int>> adj[N]; vector<int> path; bool vis[N],vis2[N]; int dfs(int u){ if(vis2[u])return u; if(vis[u])return -1; vis[u]=vis2[u]=true; for(auto [v,id]:adj[u]){ path.emplace_back(id); int res=dfs(v); if(res!=-1)return res; path.pop_back(); } vis2[u]=false; return -1; } variant<bool, vector<int>> find_journey(int N,int M,vector<int> U,vector<int> V){ n=N,m=M; for(int i=0;i<m;i+=2)adj[U[i]].emplace_back(V[i],i); int res=dfs(0); if(res==-1)return false; auto ans=path; vector<int> path2; stack<int> rev; int cur=0; bool ok=false; for(auto i:path){ if(cur==res)ok=true; if(!ok){ rev.emplace(i); }else{ path2.emplace_back(i); } cur=V[i]; } for(auto i:path2){ ans.emplace_back(i+1); } reverse(path2.begin(),path2.end()); for(auto i:path2){ ans.emplace_back(i); } for(auto i:path2){ ans.emplace_back(i+1); } while(!rev.empty()){ ans.emplace_back(rev.top()); rev.pop(); } 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...