이 제출은 이전 버전의 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<int>> arr(N);
map<pair<int,int>,int> mp;
for (int i = 0; i < M; i++){
mp[{U[i],V[i]}]=i;
arr[U[i]].push_back(V[i]);
}
if (N>2 && arr[0].size()<=1) {
cerr<<"allah allah"<<endl;
return false;
}
vector<int> par(N,-1);
vector<vector<int>> lol(N);
queue<pair<int,int>> q;
q.push({0,-2});
while (q.size()){
int node = q.front().first;
int lnode = q.front().second;
q.pop();
if (par[node]!=-1) continue;
if (lnode!=-2) lol[lnode].push_back(node);
par[node]=lnode;
for (auto it : arr[node]){
q.push({it,node});
}
}
for (int i = 1; i < N; i++){
if (par[i]==-1) {
assert(false);
cerr<<"ulasamadim"<<endl;
return false;
}
}
vector<int> ans;
bool boolean=false;
function<void(int)> dfs = [&](int node){
for (auto it : lol[node]){
if (boolean){
ans.push_back(mp[{it,node}]);
}
else ans.push_back(mp[{node,it}]);
dfs(it);
if (boolean){
ans.push_back(mp[{node,it}]);
}
else ans.push_back(mp[{it,node}]);
}
};
dfs(0);
boolean=true;
dfs(0);
/*
int nn = 0;
vector<int> used(M,0);
for (int i = 0; i < ans.size(); i++){
assert(ans[i]>=0 && ans[i]<M);
if (used[ans[i]]){
assert(V[ans[i]]==nn);
nn=U[ans[i]];
used[ans[i]]=0;
}
else {
assert(U[ans[i]]==nn);
nn=V[ans[i]];
used[ans[i]]=1;
}
}
assert(nn==0);
for (int i = 0; i < M; ++i)
{
assert(used[i]%2==0);
}
*/
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... |