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 <cassert>
#include <cstdio>
#include <variant>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) {
if (N == 2){
if(count(U.begin(), U.end(), 0) >= 2 && count(U.begin(), U.end(), 1) >= 1){
vector<pair<int, int>> ans(M);
for(int i = 0; i < M; i ++){
ans[i] = {U[i], i};
}
sort(ans.begin(), ans.end());
vector<int> ret = {ans[0].second, ans.back().second, ans[1].second, ans[0].second, ans.back().second, ans[1].second};
return ret;
}
return false;
}
bool N2 = true;
for(int i = 0; i < N; i ++){
N2 &= ((count(U.begin(), U.end(), i) + count(V.begin(), V.end(), i)) == 2 * N - 2);
}
if(N2){
vector<vector<pair<int, int>>> tree(N);
for(int i = 0; i < M; i ++){
tree[U[i]].push_back({V[i], i});
}
for(int i = 0; i < N; i ++){
sort(tree[i].begin(), tree[i].end());
}
vector<int> ret = {tree[0][0].second, tree[1][0].second, tree[0][1].second, tree[2][0].second, tree[1][0].second, tree[0][0].second, tree[2][0].second, tree[0][1].second};
return ret;
}
vector<vector<pair<int,int>>> tree(N);
for(int i = 0; i < M; i ++){
tree[U[i]].push_back({V[i], i});
}
int id = 0, par = -1;
bool back = false;
int NNN = 0;
while(tree[id].size() < 3 && !back){
NNN = max(NNN, (int)tree[id].size());
//cout << id << endl;
if(tree[id].size() == 1){
par = id;
id = tree[id][0].first;
}
else{
if(tree[id][0].first == par){
par = id;
id = tree[id][1].first;
}
else{
par = id;
id = tree[id][0].first;
}
}
if(id == 0){
back = true;
}
}
//back |= tree[0].size() > 1;
//cout << NNN << " " << back << " " << tree[0].size() << " " << id << " " << tree[id].size() << endl;
if(back || tree[0].size() == 0){
return false;
}
else{
vector<int> ans = {0, 0, 0};
return ans;
}
}
# | 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... |