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;
#define pb push_back
#define fr first
#define sc second
#define mp make_pair
#define all(x) x.begin(),x.end()
const int maxn = 2e5+10;
int n, m, tin[maxn], low[maxn], mark[maxn], iscyc[maxn], can0[maxn], timer;
int Ug[maxn], Vg[maxn];
vector<int> g[maxn], gt[maxn];
vector<pair<int,int>> gid[maxn];
map<int,vector<int>> boats[maxn];
vector<int> cur, final;
int rec[maxn];
void dfs(int u) {
rec[u] = 1;
mark[u] = 1;
if(final.size()) return;
for(auto V : gid[u]) if(V.sc%2 == 0) {
if(final.size()) return;
int v = V.fr;
if(rec[v]) {
final = cur;
vector<int> cyc;
cyc.pb(V.sc);
while(final.size() && Vg[final.back()] != v) {
cyc.pb(final.back());
final.pop_back();
}
int aux = final.size()-1;
reverse(all(cyc));
for(auto x : cyc) final.pb(x);
for(auto x : cyc) final.pb(x+1);
reverse(all(cyc));
for(auto x : cyc) final.pb(x);
for(auto x : cyc) final.pb(x+1);
for(int i = aux; i >= 0; i--) {
final.pb(i);
}
return;
}
if(mark[v]) continue;
cur.pb(V.sc);
dfs(v);
cur.pop_back();
}
rec[u] = 0;
}
void dfs0(int u) {
can0[u] = 1;
for(auto v : g[u]) {
if(can0[v] == 0) dfs0(v);
}
}
variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) {
n = N;
m = M;
for(int i = 0; i < m; i++) {
Ug[i] = U[i];
Vg[i] = V[i];
g[U[i]].pb(V[i]);
gid[U[i]].pb(mp(V[i],i));
gt[V[i]].pb(U[i]);
boats[U[i]][V[i]].pb(i);
}
dfs(0);
dfs0(0);
if(final.size()) {
return final;
}
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... |