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>
using namespace std;
const int maxN = 1e5 + 20;
vector<pair<int, int>> adj1[maxN];
vector<pair<int, int>> adj2[maxN];
int deg[maxN];
bool rem[maxN];
variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) {
for (int i = 0; i < M; i++) {
adj1[U[i]].emplace_back(V[i], i);
adj2[V[i]].emplace_back(U[i], i);
deg[U[i]]++;
}
deque<int> Q;
for (int i = 0; i < N; i++) {
if (deg[i] == 0) {
rem[i] = true;
Q.push_back(i);
}
}
vector<int> res;
int start = 0;
pair<int, int> nxt1, nxt2;
while (true) {
while (!Q.empty()) {
int u = Q.front();
for (auto e: adj2[u]) {
int v = e.first;
deg[v]--;
if (deg[v] == 0) {
rem[v] = true;
Q.push_back(v);
}
}
}
if (rem[start]) {
return false;
}
nxt1 = {-1, -1};
nxt2 = {-1, -1};
for (auto e: adj1[start]) {
if (!rem[e.first]) {
if (nxt1.first == -1) {
nxt1 = e;
}
else if (nxt2.first == -1) {
nxt2 = e;
}
}
}
if (nxt1.first == -1) {
return false;
}
if (nxt2.first == -1) {
rem[start] = true;
for (auto e: adj2[start]) {
int v = e.first;
deg[v]--;
if (deg[v] == 0) {
rem[v] = true;
Q.push_back(v);
}
}
start = nxt1.first;
}
else {
break;
}
}
return true;
}
# | 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... |