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 <bits/stdc++.h>
#include "islands.h"
using namespace std;
typedef long long ll;
int n, m;
vector<vector<pair<int, int>>> adj, revAdj; // edgeId, node
vector<bool> vst;
unordered_multiset<ll> has;
bool poss(int cur) {
if (vst[cur]) return false;
vst[cur] = true;
int cnt = 0;
for (auto &e : adj[cur]) {
ll hash = ((ll)min(cur, e.second) << 31) | max(cur, e.second);
if (!has.count(hash)) continue;
has.erase(hash);
if (poss(e.second)) return true;
cnt++;
}
return cnt >= 2;
}
variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) {
n = N; m = M;
adj = vector<vector<pair<int, int>>>(n);
for (int i = 0; i < m; i++) {
adj[U[i]].push_back({i, V[i]});
if (U[i] < V[i]) {
ll hash = ((ll)U[i] << 31) | V[i];
has.insert(hash);
}
}
vst = vector<bool>(n);
return poss(0);
}
#ifdef TEST
#include "grader.cpp"
#endif
# | 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... |