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, int par) {
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;
if (has.count(hash) == 1 && e.second == par) continue;
if (poss(e.second, cur)) 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, -1);
}
#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... |