#include "islands.h"
#include <bits/stdc++.h>
#include <variant>
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define watch(x) cout << (#x) << " = " << x << '\n'
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
map < pair<int,int>,vector<int> > cnt;
vector < int > ans;
bool ok = true;
void dfs(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]);
}
void go(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]);
}
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++){
dfs(i,i+1);
}
for(int i = N-2; i >= 0; i--){
go(i,i+1);
if(!ok) return false;
}
return ans;
}
Compilation message
islands.cpp: In function 'void dfs(int, int)':
islands.cpp:20:19: warning: variable 'B' set but not used [-Wunused-but-set-variable]
20 | pair<int,int> B = {b, a};
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
34 ms |
4424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
852 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
34 ms |
4424 KB |
Output is correct |
8 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |