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>
#include <variant>
using std::cin;
using std::cout;
using std::endl;
using std::vector;
using std::string;
using ll = int;
using vi = vector<ll>;
using vii = vector<vi>;
using pii = std::pair<ll,ll>;
#define rep(i,j,k) for(ll i=ll(j); i<ll(k); i++)
#define REP(i,j,k) for(ll i=ll(j); i<=ll(k); i++)
#define per(i,j,k) for(ll i=ll(j); i>=ll(k); i--)
#define pb emplace_back
#define ln "\n"
std::variant<bool, std::vector<int>> find_journey(int N, int M, std::vector<int> U, std::vector<int> V) {
assert(N <= 1000 && M%2 == 0);
vii edge(N), index(N);
rep(i,0,M){
edge[U[i]].pb(V[i]);
index[U[i]].pb(i);
}
if(edge[0].size() <= 1) return false;
vi ans;
vii nedge(N), nindex(N);
{
vector<bool> flag(N);
std::queue<ll> que;
que.push(0);
flag[0] = true;
while(!que.empty()){
ll now = que.front(); que.pop();
rep(i,0,edge[now].size()){
ll next = edge[now][i];
if(flag[next]) continue;
flag[next] = true;
nedge[now].pb(next);
nindex[now].pb(index[now][i]);
que.push(next);
}
}
}
std::function<void(ll)> dfs = [&](ll now){
rep(i,0,nedge[now].size()){
ll next = nedge[now][i];
ans.pb(nindex[now][i]);
dfs(next);
ans.pb(nindex[now][i]^1);
}
};
dfs(0);
ll len = ans.size();
if(len != (N-1)*2) return false;
rep(i,0,len) ans.pb(ans[i]^1);
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... |