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;
map<pair<int,int>,vector<int>> cnt;
vector<int> ans;
bool ok = true;
void go1(int a,int b){
pair<int,int> A = {a,b};
pair<int,int> B = {b,a};
if(cnt[A].size() == 0){
ok = false;
return;
}
ans.push_back(cnt[A][0]);
return;
}
void go2(int a,int b){
pair<int,int> A = {a,b};
pair<int,int> B = {b,a};
if(cnt[B].size() == 0){
ok = false;
return;
}
ans.push_back(cnt[B][0]);
if(cnt[A].size() < 2){
ok = false;
return;
}
ans.push_back(cnt[A][1]);
ans.push_back(cnt[A][0]);
ans.push_back(cnt[B][0]);
ans.push_back(cnt[A][1]);
return;
}
std::variant<bool, std::vector<int>> find_journey(
int N, int M, std::vector<int> U, std::vector<int> V) {
for(int i = 0; i < M; i++){
cnt[{U[i],V[i]}].push_back(i);
}
for(int i = 0; i + 1 < N; i++){
go1(i,i+1);
}
for(int i = N-2; i >= 0; i--){
go2(i,i+1);
if(!ok)
return false;
}
return ans;
}
Compilation message (stderr)
islands.cpp: In function 'void go1(int, int)':
islands.cpp:13:19: warning: variable 'B' set but not used [-Wunused-but-set-variable]
13 | pair<int,int> B = {b,a};
| ^
# | 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... |