제출 #826397

#제출 시각아이디문제언어결과실행 시간메모리
826397alvingogo수천개의 섬 (IOI22_islands)C++17
10.15 / 100
34 ms6968 KiB
#include "islands.h" #include <bits/stdc++.h> #include <variant> #define fs first #define sc second using namespace std; vector<vector<pair<int,int> > > e; vector<int> dep,fa; vector<int> ss; vector<int> ans; int dfs(int r,int f){ dep[r]=dep[f]+1; fa[r]=f; for(auto h:e[r]){ if(ss[h.sc/2]){ continue; } ss[h.sc/2]=1; if(dep[h.fs]==-1){ if(dfs(h.fs,r)){ return 1; } } else if(dep[h.fs]>=0){ vector<int> bz; for(int i=0;i!=h.fs;){ for(auto w:e[i]){ if(dep[w.fs]==dep[i]+1){ bz.push_back(w.sc); i=w.fs; break; } } } vector<int> cz,dz; for(int i=h.fs;i!=r;){ for(auto w:e[i]){ if(dep[w.fs]==dep[i]+1 && ss[w.sc/2]){ cz.push_back(w.sc); dz.push_back(w.sc^1); i=w.fs; break; } } } cz.push_back(h.sc); dz.push_back(h.sc^1); reverse(dz.begin(),dz.end()); ans.insert(ans.end(),bz.begin(),bz.end()); ans.insert(ans.end(),cz.begin(),cz.end()); ans.insert(ans.end(),dz.begin(),dz.end()); reverse(bz.begin(),bz.end()); reverse(cz.begin(),cz.end()); reverse(dz.begin(),dz.end()); ans.insert(ans.end(),cz.begin(),cz.end()); ans.insert(ans.end(),dz.begin(),dz.end()); ans.insert(ans.end(),bz.begin(),bz.end()); return 1; } } dep[r]=-2; return 0; } variant<bool, vector<int>> find_journey( int n, int m, vector<int> u, vector<int> v) { e.resize(n); fa.resize(n); ss.resize(m); dep.resize(n,-1); for(int i=0;i<m;i++){ e[u[i]].push_back({v[i],i}); } if(!dfs(0,0)){ 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...