이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |