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;
typedef long long ll;
typedef pair<int,int> pii;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
vector<int> vis, block;
vector<vector<pii>> edges;
vector<int> dfs(int x) {
vis[x] = 1;
for(auto [viz,ind] : edges[x]) {
if(block[viz]) continue;
if(vis[viz]) return {ind};
vector<int> v = dfs(viz);
if(!v.empty()) {v.pb(ind); return v;}
}
block[x] = 1;
return {};
}
variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) {
edges.resize(N);
vis.resize(N);
block.resize(N);
for(int i = 0; i < M; i += 2) edges[U[i]].pb({V[i], i});
vector<int> c = dfs(0), ans;
if(c.empty()) return false;
reverse(all(c));
int x = V[c.back()], m = 0;
for(int i = sz(c) - 1; i >= 0; i--) if(U[i] == x) m = i;
// PARTE 1
for(int i = 0; i < sz(c); i++) ans.pb(c[i]);
for(int i = m-1; i >= 0; i--) ans.pb(c[i]);
// PARTE 2
for(int i = 0; i < sz(c); i++) ans.pb(c[i] + 1);
for(int i = m-1; i >= 0; i--) ans.pb(c[i] + 1);
// PARTE 3
for(int i = 0; i < m; i++) ans.pb(c[i]);
for(int i = sz(c) - 1; i >= m; i--) ans.pb(c[i]);
for(int i = m-1; i >= 0; i--) ans.pb(c[i]);
// PARTE 4
for(int i = 0; i < m; i++) ans.pb(c[i] + 1);
for(int i = sz(c) - 1; i >= m; i--) ans.pb(c[i] + 1);
for(int i = m-1; i >= 0; i--) ans.pb(c[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... |