제출 #1070308

#제출 시각아이디문제언어결과실행 시간메모리
1070308Unforgettablepl수천개의 섬 (IOI22_islands)C++17
24 / 100
26 ms6352 KiB
#include "islands.h" #include <bits/stdc++.h> using namespace std; variant<bool, vector<int>> find_journey(int N,int M,vector<int> U,vector<int> V){ vector<vector<pair<int,int>>> adj(N); for(int i=0;i<M;i+=2) { adj[U[i]].emplace_back(V[i],i); } vector<int> visited(N); stack<int> path; function<bool(int)> dfs = [&](int x) { if(visited[x]==2)return false; if(visited[x]==1){ return true; } visited[x]=1; for(auto&[v,idx]:adj[x]) { path.emplace(idx); if(dfs(v))return true; path.pop(); } visited[x]=2; return false; }; if(!dfs(0))return false; vector<int> path_cycle,path_direct; int ver = V[path.top()]; bool phase = false; while(!path.empty()) { int curr = path.top();path.pop(); if(!phase)path_cycle.emplace_back(curr); else path_direct.emplace_back(curr); if(U[curr]==ver)phase=true; } reverse(path_cycle.begin(),path_cycle.end()); reverse(path_direct.begin(),path_direct.end()); vector<int> ans = path_direct; for(int&i:path_cycle)ans.emplace_back(i); for(int&i:path_cycle)ans.emplace_back(i+1); reverse(path_cycle.begin(), path_cycle.end()); for(int&i:path_cycle)ans.emplace_back(i); for(int&i:path_cycle)ans.emplace_back(i+1); reverse(path_direct.begin(),path_direct.end()); for(int&i:path_direct)ans.emplace_back(i); 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...