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"
#ifdef NYAOWO
#include "grader.cpp"
#endif
#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
// #define int LL
using namespace std;
using i32 = int32_t;
using LL = long long;
using pii = pair<int, int>;
vector<int> link(vector<int> v, vector<int> o, bool rev = false) {
if(rev) reverse(all(o));
v.insert(v.end(), all(o));
return v;
}
vector<int> solve_bidir_loop(int n, vector<int> cy, vector<int> yc) {
vector<int> res;
res = link(res, cy);
res = link(res, yc, true);
res = link(res, cy, true);
res = link(res, yc);
return res;
}
variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) {
// if (N == 4) {
// return vector<int>({0, 1, 2, 4, 0, 3, 2, 1, 4, 3});
// }
// return false;
if(N == 2) {
vector<int> e0, e1;
For(i, 0, M - 1) {
if(U[i] == 0) e0.eb(i);
else e1.eb(i);
}
if(sz(e0) >= 2 && sz(e1) >= 1) {
int a = e0[0], b = e0[1];
int c = e1[0];
return vector<int>({b, c, a, b, c, a});
}
return false;
}
int id[3][3] = {-1};
For(i, 0, M - 1) {
int x = U[i];
int y = V[i];
if(x < 3 && y < 3) {
id[x][y] = i;
}
}
vector<int> res = solve_bidir_loop(3, {id[0][1], id[1][2], id[2][0]}, {id[1][0], id[2][1], id[0][2]});
return res;
}
/*
4 5
0 1
1 2
2 3
0 3
3 1
1
10
0 1 2 4 0 3 2 1 4 3
2 3
0 1
1 0
1 0
0
0
*/
# | 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... |