이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "islands.h"
#include <variant>
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define all(a) (a).begin(), (a).end()
#define ll long long
const int mod = 1000002022;
vector<int> state, p;
int n, m;
vector<vector<int>> g;
template<typename T>
int len(T &a){return a.size();}
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
variant<bool, vector<int>> find_journey(
int n, int m, std::vector<int> u, std::vector<int> v) {
vector<vector<int>> g(n);
for(int i = 0; i < m; i ++) g[u[i]].push_back(i);
if(len(g[0]) == 0) return false;
if(n == 2){
if(len(g[0]) <= 1) return false;
if(len(g[1]) == 0) return false;
return vector {g[0][0], g[1][0], g[0][1], g[0][0], g[1][0], g[0][1]};
}
if(len(g[0]) == 2){
int a = g[0][0], b = g[0][1];
return vector{a, a ^ 1, b, b ^ 1, a ^ 1, a, b ^ 1, b};
}
vector<int> ans = {g[0][0]};
int cnt = 0;
vector<int> cyc;
while(true){
int cur = v[ans.back()];
cnt ++;
if(len(g[cur]) <= 1){
return false;
}
if(len(g[cur]) >= 3){
vector<int> v;
for(int j = 0; j < 3; j ++) if(g[cur][j] != (ans.back() ^ 1)) v.push_back(g[cur][j]);
int a = v[0], b = v[1];
cyc = vector{a, a ^ 1, b, b ^ 1, a ^ 1, a, b ^ 1, b};
break;
}
if(g[cur][0] == (ans.back() ^ 1)){
ans.push_back(g[cur][1]);
}else ans.push_back(g[cur][0]);
}
vector<int> res = ans;
for(auto u : cyc) res.push_back(u);
reverse(all(ans));
for(auto u : ans) res.push_back(u);
return res;
}
# | 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... |