제출 #834896

#제출 시각아이디문제언어결과실행 시간메모리
834896Username4132수천개의 섬 (IOI22_islands)C++17
35 / 100
52 ms21696 KiB
#include "islands.h" #include <variant> #include<iostream> #include <vector> #include<cassert> using namespace std; using pii = pair<int, int>; #define forn(i, n) for(int i=0; i<(int)n; ++i) #define PB push_back #define F first #define S second const int MAXN = 100010; int n, m, cur, stpos[MAXN]; bool vis[MAXN], blocked[MAXN], inst[MAXN]; vector<int> st, se; vector<pii> g[MAXN]; bool dfs2(int v){ inst[v]=true; vis[v]=true; for(pii to:g[v]) if(!vis[to.F] && !blocked[to.F]) { bool ret = dfs2(to.F); if(ret) return true; } else if((inst[to.F] || stpos[to.F]!=-1) && !blocked[to.F] && to.S != se[cur]){ return true; } inst[v]=false; return false; } int dfs1(int v){ stpos[v]=(int)st.size(); st.PB(v); vis[v]=true; for(pii to:g[v]) if(!vis[to.F] && !blocked[to.F]){ se.PB(to.S); int ret = dfs1(to.F); if(ret) return ret; } else if(stpos[to.F]!=-1){ while(cur<=stpos[to.F]){ bool ret = dfs2(st[cur]); if(ret) return 1; blocked[st[cur]]=true; ++cur; } } if((int)st.size() <= cur+1) return 2; st.pop_back(); se.pop_back(); stpos[v]=-1; return 0; } variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) { n=N, m=M; forn(i, n) stpos[i]=-1; forn(i, m) g[U[i]].PB({V[i], i}); int ret = dfs1(0); if(ret==1){ vector<int> ans; 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...