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 <variant>
#include <vector>
#include<bits/stdc++.h>
using namespace std;
int odw[100010];
vector<pair<int, int>>graf[100010];
vector<int>ans;
vector<int>stos;
bool czy[100010];
vector<int>stos2;
void dfs(int x, int kra){
czy[x] = 1;
stos2.push_back(x);
/*
if(graf[x].size()>2){
int pom = graf[x][0].second, pom1 = graf[x][1].second;
if(pom/2==kra/2)
pom = graf[x][2].second;
if(pom1/2==kra/2)
pom1 = graf[x][2].second;
ans = stos;
vector<int>POM = {pom, pom^1, pom1, pom1^1, pom^1, pom, pom1^1, pom1};
for(auto j: POM)
ans.push_back(j);
while(stos.size()){
ans.push_back(stos.back());
stos.pop_back();
}
return;
}*/
for(auto j: graf[x]){
if(kra/2!=j.second/2){
odw[j.first]++;
if(czy[j.first]){
ans = stos;
ans.push_back(j.second);
vector<int>pomstos = {j.second^1};
while(stos2.back()!=j.first){
pomstos.push_back(stos.back());
stos.pop_back();
stos2.pop_back();
}
for(auto j: pomstos)ans.push_back(j^1);
reverse(pomstos.begin(), pomstos.end());
for(auto j: pomstos)ans.push_back(j);
for(auto j: pomstos)ans.push_back(j^1);
while(stos.size()){
ans.push_back(stos.back());
stos.pop_back();
}
return;
}
if(odw[j.first]==1){
stos.push_back(j.second);
dfs(j.first, j.second);
if(ans.size())return;
stos.pop_back();
}
}
}
czy[x] = 0;
stos2.pop_back();
}
std::variant<bool, std::vector<int>> find_journey(int n, int m, std::vector<int> U, std::vector<int> V) {
int i;
for(i=0;i<m;i+=2){
graf[U[i]].push_back({V[i], i});
//graf[V[i]].push_back({U[i], i+1});
}
odw[0] = 1;
dfs(0, -2);
if(ans.size()>0)return true;
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... |