이 제출은 이전 버전의 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){
if((int)adj[ver].size()>=3-(ver==0)){
int a=-1, b=-1, c, d;
for(auto u : adj[ver]){
if((u.se>>1)==(cam.back()>>1)) continue;
if(a==-1)
a=u.se;
else{
b=u.se;
break;
}
}
if(a&1) c=a-1;
else c=a+1;
if(b&1) d=b-1;
else d=b+1;
vector<int> temp=cam;
reverse(all(temp));
cam.pb(a); cam.pb(c);
cam.pb(b); cam.pb(d);
cam.pb(c); cam.pb(a);
cam.pb(d); cam.pb(b);
for(auto u : temp) cam.pb(u);
return 1;
}
for(auto [a, b]: adj[ver]){
if(a==prev) continue;
cam.pb(b);
if(calc(a, ver, adj, cam)) return 1;
cam.pop_back();
}
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;
if(calc(0, -1, adj, ans)) 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... |