이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "islands.h"
//~ #include <variant>
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef complex<double> cd;
bool calc(int ver, int prev, vector<vector<pii>>& adj, vector<int>& cam, vector<int>& path, vector<int>& viz){
viz[ver]=1;
path.pb(ver);
for(int i=0;i<(int)adj[ver].size();i+=2){
pii u=adj[ver][i];
if(viz[u.fi]==2) continue;
if(viz[u.fi]==0){
cam.pb(u.se);
if(calc(u.fi, ver, adj, cam, path, viz)) return 1;
cam.pop_back();
}
else{
cam.pb(u.se);
int ptrcam=(int)cam.size()-2, ptrpath=(int)path.size()-1;
vector<int> rep={u.se};
do{
rep.pb(cam[ptrcam--]);
ptrpath--;
}while(path[ptrpath]!=u.fi);
vector<int> aux=cam;
reverse(all(aux));
reverse(all(rep));
for(auto at : rep) cam.pb(at+1);
reverse(all(rep));
for(auto at : rep) cam.pb(at);
for(auto at : rep) cam.pb(at+1);
for(int j=(int)rep.size();j<(int)aux.size();j++) cam.pb(aux[j]);
return 1;
}
}
path.pop_back();
viz[ver]=2;
return 0;
}
variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) {
vector<vector<pii>> adj(N);
for(int i=0;i<M;i++)
adj[U[i]].pb({V[i], i});
if(N==2){
if((int)adj[0].size()>=2 && adj[1].size()>=1){
int a=adj[0][0].se, b=adj[0][1].se, c=adj[1][0].se;
return vector<int>({a, c, b, a, c, b});
}
return false;
}
vector<int> ans, aux, viz(N, 0);
if(calc(0, -1, adj, ans, aux, viz)) return ans;
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... |