This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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) {
set<pair<int,int>> st;
vector<vector<int>> arr(N);
map<pair<int,int>,int> mp;
for (int i = 0; i < M; i++){
mp[{U[i],V[i]}]=i;
if (st.find({V[i],U[i]})!=st.end()) continue;
st.insert({U[i],V[i]});
arr[U[i]].push_back(V[i]);
arr[V[i]].push_back(U[i]);
}
if (arr[0].size()<=1) 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});
}
}
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);
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... |