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;
#define MAX 201010
int deg[MAX];
vector<int> adj[MAX];
vector<int> radj[MAX];
int chk[MAX];
int N, M;
variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) {
int i;
::N = N;
::M = M;
for (i = 0; i < M; i++) deg[U[i]]++, adj[U[i]].push_back(i), radj[V[i]].push_back(U[i]);
queue<int> q;
for (i = 0; i < N; i++) if (!deg[i]) q.push(i);
int s = 0;
vector<int> st;
while (1) {
while (q.size()) {
int t = q.front();
chk[t] = 1;
q.pop();
for (auto v : radj[t]) if (!chk[v]) {
deg[v]--;
if (deg[v] == 0) q.push(v);
}
}
if (deg[s] <= 1) {
if (deg[s] == 0) return false;
for (auto n : adj[s]) {
if (!chk[V[n]]) {
for (auto v : radj[s]) if (!chk[v]) {
deg[v]--;
if (deg[v] == 0) q.push(v);
}
chk[s] = 1;
s = V[n];
st.push_back(n);
break;
}
}
if (deg[s] == 0) return false;
continue;
}
else break;
}
return vector<int>(1, 2);
vector<int> ans = st;
int a, b;
a = b = -1;
for (auto n : adj[s]) if (!chk[V[n]]) b = a, a = n;
}
# | 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... |