이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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, rec[maxn];
int Ug[maxn], Vg[maxn];
vector<int> g[maxn], gt[maxn];
vector<pair<int,int>> gid[maxn];
map<int,vector<int>> boats[maxn];
map<int,int> boat[maxn];
vector<int> cur, final;
bool ans = 0;
void dfs(int u) {
mark[u] = 1;
rec[u] = 1;
if(ans) return;
set<int> st;
for(auto V : gid[u]) if(V.sc%2 == 0) {
if(st.count(V.fr)) continue;
st.insert(V.fr);
if(ans) return;
int v = V.fr;
if(rec[v]) {
ans = 1;
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 = (int) 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(final[i]);
}
return;
}
if(!mark[v]) {
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]);
boat[U[i]][V[i]] = i;
}
if(n == 2) return false;
// 0 -> 1 -> 2 -> 0 -> 2 -> 1 -> 0
return vector<int>{boat[0][1],boat[1][2],boat[2][0],boat[0][2],boat[2][1],boat[1][0],boat[2][0],boat[1][2],boat[0][1],boat[1][0],boat[2][1],boat[0][2]};
dfs(0);
dfs0(0);
if(ans) {
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... |