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 <map>
#include <queue>
using namespace std;
vector<int> U, V;
int N, M;
vector<vector<int>> adj;
bool path_exists(int target) {
vector<bool> vis(N);
queue<int> q;
q.push(0);
vis[0] = true;
while (!q.empty()) {
int x = q.front(); q.pop();
if (x == target) return true;
for (auto c : adj[x]) {
if (!vis[V[c]]) {
vis[V[c]] = true;
q.push(V[c]);
}
}
}
return false;
}
variant<bool, vector<int>> find_journey(
int N, int M, vector<int> U, vector<int> V) {
::U = U;
::V = V;
::N = N;
::M = M;
adj.resize(N);
for (int i = 0; i < M; i++)
adj[U[i]].push_back(i);
if (adj[0].size() >= 2)
return true;
for (int i = 0; i < N; i++) {
if (adj[i].size() >= 3 && path_exists(i))
return true;
}
return false;
}
# | 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... |