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"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long double ld;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ms memset
#define pb push_back
#define fi first
#define se second
variant<bool, vi> find_journey(int N, int M, vi U, vi V) {
if (N == 2){
vi e0, e1;
FOR(i,0,M){
if (U[i]==0) e0.pb(i);
else e1.pb(i);
}
if (e0.size() < 2 || e1.size() < 1) return false;
return vi({e0[0], e1[0], e0[1], e0[0], e1[0], e0[1]});
}
if (N <= 400 && M == N*(N-1)){
vii p = {{0,1},{1,2},{2,0},{0,2},{2,1},{1,0}};
vi l(6);
FOR(i,0,M){
FOR(j,0,6){
if (p[j] == ii({U[i],V[i]})){
l[j] = i;
}
}
}
return vi({l[0],l[1],l[2],l[3],l[4],l[5],l[2],l[1],l[0],l[5],l[4],l[3]});
}
if (N <= 1000 && U[0] != U[1]){
int mat[N][N][2];
ms(mat, -1, sizeof(mat));
FOR(i,0,M){
// labelling edges
int pos = 0;
if (mat[U[i]][V[i]][0] != -1) pos = 1;
mat[U[i]][V[i]][pos] = i;
}
vi p(N);
vi bfs; bfs.pb(0);
vi used(N); used[0] = 1;
FOR(k,0,bfs.size()){
int u = bfs[k];
FOR(i,0,N){
if (mat[u][i][0] == -1) continue;
if (used[i] && p[u] != i && p[i] != u){
// cycle found
cout << "CYCLE\n";
vi paru; int v = u;
while (v != 0){
paru.pb(v);
v = p[v];
}
paru.pb(0);
vi pari; v = i;
while (v != 0){
pari.pb(v); v = p[v];
}
pari.pb(0);
reverse(paru.begin(),paru.end());
reverse(pari.begin(),pari.end());
int a = 0;
vi ans;
//path from 0 to cycle
FOR(j,1,min(paru.size(),pari.size())){
if (paru[j] == pari[j]){
ans.pb(mat[paru[j-1]][paru[j]][0]);
a=j;
}else{
break;
}
}
//first loop
FOR(j,a+1,paru.size()){
ans.pb(mat[paru[j-1]][paru[j]][0]);
}
ans.pb(mat[u][i][0]);
ROF(j,pari.size()-1,a+1){
ans.pb(mat[pari[j]][pari[j-1]][0]);
}
//second loop
FOR(j,a+1,pari.size()){
ans.pb(mat[pari[j-1]][pari[j]][0]);
}
ans.pb(mat[i][u][0]);
ROF(j,paru.size()-1,a+1){
ans.pb(mat[paru[j]][paru[j-1]][0]);
}
//reverse 1st loop
FOR(j,a+1,pari.size()){
ans.pb(mat[pari[j]][pari[j-1]][0]);
}
ans.pb(mat[u][i][0]);
ROF(j,paru.size()-1,a+1){
ans.pb(mat[paru[j-1]][paru[j]][0]);
}
//reverse 2nd loop
FOR(j,a+1,paru.size()){
ans.pb(mat[paru[j]][paru[j-1]][0]);
}
ans.pb(mat[i][u][0]);
ROF(j,pari.size()-1,a+1){
ans.pb(mat[pari[j-1]][pari[j]][0]);
}
//path back to 0
ROF(j,a,1){
ans.pb(mat[paru[j]][paru[j-1]][0]);
}
return ans;
}
if (mat[u][i][1] != -1 && p[u] != i && p[i] != u){
cout << "GG";
// double edge found, solution from Subtask 1
vi par; int v = u;
while (v != 0){
par.pb(v);
v = p[v];
}
par.pb(0);
reverse(par.begin(), par.end());
vi ans;
FOR(j,0,par.size()-1){
ans.pb(mat[par[j]][par[j+1]][0]); //path 0 -> u
}
// e0[0], e1[0], e0[1], e0[0], e1[0], e0[1]
vi path = {mat[u][i][0], mat[i][u][0], mat[u][i][1], mat[u][i][0], mat[i][u][0], mat[u][i][1]};
FOR(j,0,6) ans.pb(path[j]);
ROF(j,par.size()-2,0){
ans.pb(mat[par[j]][par[j+1]][0]); //path u -> 0
}
return ans;
}
used[i] = 1; p[i] = u;
bfs.pb(i);
}
}
}
return false;
}
Compilation message (stderr)
islands.cpp: In function 'std::variant<bool, std::vector<int, std::allocator<int> > > find_journey(int, int, vi, vi)':
islands.cpp:11:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | #define FOR(i, a, b) for(int i = a; i < b; i++)
......
52 | FOR(k,0,bfs.size()){
| ~~~~~~~~~~~~~~
islands.cpp:52:5: note: in expansion of macro 'FOR'
52 | FOR(k,0,bfs.size()){
| ^~~
islands.cpp:11:39: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
11 | #define FOR(i, a, b) for(int i = a; i < b; i++)
......
75 | FOR(j,1,min(paru.size(),pari.size())){
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
islands.cpp:75:11: note: in expansion of macro 'FOR'
75 | FOR(j,1,min(paru.size(),pari.size())){
| ^~~
islands.cpp:11:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | #define FOR(i, a, b) for(int i = a; i < b; i++)
......
84 | FOR(j,a+1,paru.size()){
| ~~~~~~~~~~~~~~~~~
islands.cpp:84:11: note: in expansion of macro 'FOR'
84 | FOR(j,a+1,paru.size()){
| ^~~
islands.cpp:11:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | #define FOR(i, a, b) for(int i = a; i < b; i++)
......
92 | FOR(j,a+1,pari.size()){
| ~~~~~~~~~~~~~~~~~
islands.cpp:92:11: note: in expansion of macro 'FOR'
92 | FOR(j,a+1,pari.size()){
| ^~~
islands.cpp:11:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | #define FOR(i, a, b) for(int i = a; i < b; i++)
......
100 | FOR(j,a+1,pari.size()){
| ~~~~~~~~~~~~~~~~~
islands.cpp:100:11: note: in expansion of macro 'FOR'
100 | FOR(j,a+1,pari.size()){
| ^~~
islands.cpp:11:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | #define FOR(i, a, b) for(int i = a; i < b; i++)
......
108 | FOR(j,a+1,paru.size()){
| ~~~~~~~~~~~~~~~~~
islands.cpp:108:11: note: in expansion of macro 'FOR'
108 | FOR(j,a+1,paru.size()){
| ^~~
islands.cpp:11:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | #define FOR(i, a, b) for(int i = a; i < b; i++)
......
132 | FOR(j,0,par.size()-1){
| ~~~~~~~~~~~~~~~~
islands.cpp:132:11: note: in expansion of macro 'FOR'
132 | FOR(j,0,par.size()-1){
| ^~~
# | 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... |