이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "islands.h"
#include <bits/stdc++.h>
using namespace std;
std::variant<bool, std::vector<int>> find_journey(
int N, int M, std::vector<int> U, std::vector<int> V) {
vector<vector<pair<int,int>>> arr(N);
for (int i = 0; i < M; i++){
arr[U[i]].push_back({V[i],i});
}
for (int i = 0; i < N; ++i)
{
sort(arr[i].begin(), arr[i].end());
}
if (arr[0].size()==0) {
return false;
}
if (arr[0].size()>=2){
int a = arr[0][0].first;
int b = arr[0][1].first;
if (a==b){
return vector<int>{arr[0][0].second,arr[a][0].second,arr[0][1].second,arr[0][0].second,arr[a][0].second,arr[0][1].second};
}
else {
return vector<int>{
arr[0][0].second,
arr[a][0].second,
arr[0][1].second,
arr[b][0].second,
arr[a][0].second,
arr[0][0].second,
arr[b][0].second,
arr[0][1].second
};
}
}
vector<bool> vis(N,false);
vector<pair<int,int>> par(N,{-1,-1});
function<void(int)> dfs = [&](int node)->void{
if (vis[node]) return;
vis[node]=true;
for (auto it : arr[node]){
if (vis[it.first]) continue;
par[it.first]={node,it.second};
dfs(it.first);
}
};
for (int i = 1; i < N; i++){
if (arr[i].size()>=3 && vis[i]){
vector<int> ans;
int nd = i;
while (nd!=-1){
ans.push_back(par[nd].second);
nd=par[nd].first;
}
reverse(ans.begin(), ans.end());
sort(arr[i].begin(), arr[i].end(), [&](pair<int,int> a, pair<int,int> b){
return (par[i].second^1^a.second)>(par[i].second^1^b.second);
});
ans.push_back(arr[i][0].second);
ans.push_back(arr[i][0].second^1);
ans.push_back(arr[i][1].second);
ans.push_back(arr[i][1].second^1);
ans.push_back(arr[i][0].second^1);
ans.push_back(arr[i][0].second);
ans.push_back(arr[i][1].second^1);
ans.push_back(arr[i][1].second);
nd = i;
while (nd!=-1){
ans.push_back(par[nd].second);
nd=par[nd].first;
}
return ans;
}
}
assert(false);
return false;
}
# | 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... |