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>
#define pb push_back
#define ll long long
#define ff first
#define ss second
#include <variant>
#include <vector>
using namespace std;
vector<pair<int, int > >child[5005];
int devuelta[5005];
vector<pair<int, int > > adj[5005];
vector<int>tempRoute;
vector<int>rt;
bool dfs(int node, int parent){
for(int i = 0 ; i < adj[node].size() ; i ++){
if(adj[node][i].ff == parent)continue;
child[node].pb(adj[node][i]);
}
if(child[node].size() >= 2){
int a = child[node][0].ss;
int b = devuelta[child[node][0].ss];
int c = child[node][1].ss;
int d = devuelta[c];
tempRoute = {a, b, c, d, b, a, d, c};
return true;
}
for(auto i : child[node]){
if(dfs(i.ff, node)){
rt.pb(i.ss);
return true;
}
}
return false;
}
std::variant<bool, std::vector<int>> find_journey(
int N, int M, std::vector<int> U, std::vector<int> V) {
int cuenta[N][N];
vector<int>parejas[N][N];
for(int i = 0 ; i < N ; i ++){
for(int j = 0 ; j < N ; j ++){
cuenta[i][j] = 0;
}
}
for(int i = 0 ; i < M ; i ++ ){
cuenta[U[i]][V[i]] ++ ;
parejas[U[i]][V[i]].pb(i);
adj[U[i]].pb({V[i], i});
}
if (N == 2) {
if(cuenta[0][1] >= 2 and cuenta[1][0] >= 1){
int a = parejas[0][1][0];
int b = parejas[1][0][0];
int c = parejas[0][1][1];
vector<int>ans = {a, b, c, a, b, c};
return ans;
}
return false;
}else{
bool case3 = true;
if( M % 2 == 1)case3 = false;
for(int i = 0 ; i < M ; i += 2){
if(U[i] != V[i+1] or V[i] != U[i] + 1)case3 = false;
devuelta[i] = i+1;
devuelta[i+1] = i;
}
if(!case3){
int a = parejas[0][1][0];
int b = parejas[1][0][0];
int c = parejas[0][2][0];
int d = parejas[2][0][0];
vector<int>ans = {a, b, c, d, b, a, d, c};
return ans;
}else{
if(!dfs(0, -1))return false;
vector<int>ans = rt;
reverse(ans.begin(), ans.end());
for(auto i : tempRoute)ans.pb(i);
for(auto i : rt)ans.pb(i);
return ans;
}
}
}
Compilation message (stderr)
islands.cpp: In function 'bool dfs(int, int)':
islands.cpp:16:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | for(int i = 0 ; i < adj[node].size() ; i ++){
| ~~^~~~~~~~~~~~~~~~~~
# | 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... |