This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Be name khoda //
#include "islands.h"
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define debug(x) cerr << "(" << (#x) << "): " << (x) << endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
const int mod = 1e9 + 9;
const int maxn5 = 2e5 + 10;
vector <pair<int, int>> adj[maxn5];
int mark[maxn5], cyver2;
vector <int> ret;
bool dfs(int v){
mark[v] = 1;
for(auto [u, id] : adj[v]){
if(!mark[u]){
ret.pb(id);
if(dfs(u))
return true;
ret.pop_back();
}
else if(mark[u] == 1){
ret.pb(id);
cyver2 = u;
return true;
}
}
mark[v] = 2;
return false;
}
std::variant<bool, std::vector<int>> find_journey(
int n, int m, std::vector<int> u, std::vector<int> v) {
for(int i = 0; i < m; i++)
adj[u[i]].pb({v[i], i});
if(!dfs(0))
return false;
int ind = 0;
while(u[ret[ind]] != cyver2)
ind++;
int ind2 = ret.size();
for(int i = ind; i < ind2; i++)
ret.pb(ret[i] ^ 1);
for(int i = ind2 - 1; i >= ind; i--)
ret.pb(ret[i]);
for(int i = ind2 - 1; i >= ind; i--)
ret.pb(ret[i] ^ 1);
for(int i = ind - 1; i >= 0; i--)
ret.pb(ret[i]);
return ret;
}
# | 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... |