이 제출은 이전 버전의 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++){
adj[U[i]].emplace_back(V[i],i);
}
vector<bool> visited(N);
stack<int> path;
vector<int> ans;
vector<int> direction;
function<int(int,int)> dfs = [&](int x,int pedge) {
if(visited[x]) {
return x;
}
visited[x]=true;
bool found = false;
pair<int,int> idxes = {-1,-1};
for(auto&[v,idx]:adj[x])if(pedge!=idx) {
path.emplace(idx);
auto temp = dfs(v,idx^1);
if(temp==-1){
path.pop();
if(found) {
idxes.second=idx;
break;
}
idxes.first=idx;
found=true;
continue;
}
if(temp==-2) {
direction.emplace_back(idx);
return -2;
}
ans.emplace_back(idx);
if(temp!=x) {
return temp;
}
reverse(ans.begin(), ans.end());
vector<int> myans = ans;
reverse(ans.begin(), ans.end());
for(int&i:ans)myans.emplace_back(i^1);
for(int&i:ans)myans.emplace_back(i);
reverse(ans.begin(), ans.end());
for(int&i:ans)myans.emplace_back(i^1);
ans = myans;
return -2;
}
if(idxes.second!=-1) {
int a = idxes.first;
int b = idxes.second;
ans = {a,a^1,b,b^1,a^1,a,b^1,b};
return -2;
}
return -1;
};
auto temp = dfs(0,-1);
if(temp==-1)return false;
reverse(direction.begin(), direction.end());
vector<int> myans = direction;
for(int&i:ans)myans.emplace_back(i);
reverse(direction.begin(), direction.end());
for(int&i:direction)myans.emplace_back(i);
return myans;
}
# | 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... |